So I have a site workflow that runs daily that is supposed to look at a list and find ones where the "Next Review Date" == Today. For items where this is true, it's supposed to set the columns "Status" and "WFStatus" to "Expired" and then begin a list workflow for these items. The list workflow then checks to see if "Status" == Expired and if "Next Review Date" == Today and then complete some actions if so.
The issue I'm having is if there is more than one list item where "Next Review Date" == Today. For the first one, it does everything correctly. For the second one, it doesn't update the field values, but it does start the workflow. But since the conditions in the List Workflow aren't met, the list workflow exits.
Here is how the Query List Action is configured:
I tried having it give a separate output per column as well, which didn't give any different results.
Here is what's after the Query:
And here's how the For Each is set up:
I can see in the Site Workflow logs that it is seeing two items that meet the criteria and then when I go to each item in the list I can see that the list workflow was started, but on one of them, the fields haven't been updated.
Solved! Go to Solution.
The list workflow doesn't modify/update fields, it has a runIf fields == things and the Site workflow is supposed to set the fields to things. It does it for the first item, but not any further. For example, if there are three items with a Next Review Date of today, it will update the fields for the first item, but not the other two. But, it will start the list workflow on all three. Since the setting of the fields didn't happen for items two and three, the runIf condition is not met for those two.
Edit to Add: I know that the loop sees all three or two or however many items because I have a variable for the count that logs that is always correct
the issue is right there..Update Item action does an update only to one item, so looking at the configuration it search for an item where NextReviewDate = Today and it returns always the first one.
You can solve this issue if in the query list you retrieve also the ID of the item and then you get it inside the For Each, in order to update the id-related item in each loop of the for each.
Otherwise you can sobstitute the Update Item with the Office 365 Update Items action (to be put before the For Each) that allows you to update multiple items based on your condition.
Hope this help
Yes, the For Each iterate per item returned by the query, in fact it execute the update item and the start workflow for each item.
The problem is that, the condition you have set in the update item, isn't tied to any variable that is connected to the iteration but it's generic, so it will always return the same item to update.
I will do the following changes:
Query List Output:
(in this way you have a collection of all the item IDs who respect your filter)
(you take your collection and in each iteration you save the single ID value in a variable)
(in the Update Item you updating only the item with the specific ID you get from the query list and the iteration)
I think previously you were getting also the GUID in order to use it in Start Workflow Action, but I've seen that you can also use ID in order to specify on which item you want to start the list workflow, so you don't need anymore the GUID.