Compare collection items?

  • 22 September 2017
  • 7 replies
  • 101 views

Badge +2

Hi everyone!

Having a really issue with my workflow! 

Objective:

Check if list item (crane) has been submitted for today. 

1) Set current date var

2) Query list for departments

3) For Each - Department

4) Query cranes in department filtered by dept into cranecollection.

5) Query submissions list got records submitted today and return crane id's to outputcollection.

6) For Each - crane in cranecollection store in craneIN

7) Collection op - craneoutput EXISTS, value craneIN store in existCollection.

8) Set Condition - if existCollection is not empty

YES - add craneIN to completeOut   No- add craneIN to missingout.

9) clear existCollection

Loop

What am I doing wrong here? Do I need another for each loop for the outputcollecion? I've tried that where it goes through each item on the collection and I've tried comparing the variables and it just doesn't work. 


7 replies

Userlevel 5
Badge +13

Perhaps I'm misunderstanding your need. Could you not use the Check if Item Exists in Collection once you get a collection variable of items submitted today?

You could query your list and filter for "submitted/created == today" and within that, check if item exists. I'm not sure I understand the department portion of your requirement though.

Badge +2

Does the "exists" collection function check the entire collection or just the first index? Or do you have to put a for each loop with it?

When I try to query the list for "created today" the time stamp tends to stop it from working. So if I create a calculated date with today's date - x hours it works, but not in combination with & crane name variable. 

The workflow sends out an email to supervisors daily letting them know which cranes have and have not been inspected per department. The whole thing is basically contained in a for each department loop. Each department has multiple cranes that need inspection. I'm trying to check if the cranes have a record created for them that day, and if they match the department. Also collect which have not in another collection. 

Userlevel 5
Badge +13

So, you query the list to get all the departments. Then, for each department, query the list for items where department == thisDepartment (you can use the "output" of the forEach to get the department you're on) and created == today.

You can strip the time off of your todayVariable by setting the hour and minute to 0 in the "set time portion of date time field". If you're using time in your list column, then instead of looking for created == today, look for created > today . This will give you a collection of all the ones that were done today. 

Are the number of cranes consistent? As in, you know for each department how many there should be submitted daily? I would make a list of this if so, a new list called "numberOfCranes" or some such. Then, you can count your new collection and have a conditional for "does craneCollCount == numberOfCranes" and have it lookup to the list where "thisDepartment == departmentInNumberOfCranes". This way, if they've all already been submitted, you don't need to do any checking inside the variable, because you know they're all there.

The check if item exists in collection just checks in a collection for whatever value you tell it to and then spits out "true" or "false" depending on if the thing is in the collection anywhere (no index needed). I would check out the link I put in the previous post to read a bit more about this action.

Badge +2

So can yes/no variables be used for the exists bool?

I have a for each crane (store in crane ID),

Exists (craneID) in foundRecordsCollection store in bool.

Set condition bool equals yes, add craneID to outputcollection.

But it's not working? 

Userlevel 5
Badge +13

Can you log the variable that you get from Exists (craneID) in foundRecordsCollection ? As in, set it to a text variable and see how it outputs it? Then you can just do your condition textVar == TRUE (or whatever format it spits it out in).

Badge +2

I knew this wasn't making any logic sense. I tried like 4 different ways to compare the data, and per your suggestion, I tried adding an add operation to a temp list for every compare cycle and it would only report back one item, vs the list actually having 4 or 5 cranes in it. My problem is that the field I populate my cranes from was a multiple item lookup field and it treated all the items as one. I'm just going to populate from the primary list! Thanks so much for your help! 

Userlevel 5
Badge +13

So glad to be of assistance!

Reply