AnsweredAssumed Answered

For Each running in parallel instead of consecutively?

Question asked by zwholker on Nov 17, 2015
Latest reply on Nov 17, 2015 by zwholker

A bit of setup: designing a parking sign up application. It keeps track of the order in line, and when a parking spot opens up it is offered to number one in line. If they pass it's offered to number two in line, and so on. A person can only pass three times before they're bumped to the end of the line. A person can also be in line for a spot while they already have one, in which case, if they accept the offered parking spot, the spot they have becomes open and is offered.


So that's the gist of the workflow. When a spot becomes open, it runs (with that spot's record as the "current item"). It queries the list for all waiting in line, ordered by their position in line, and then one by one offers them the spot using a flexi task. If they reject it moves on, if they accept it makes the proper modifications to the list items, reorders the list, and closes. The very last action it will perform is a check if they already had a spot, and if they did, open up that spot, which thus restarts the workflow.


When the workflow is restarted is where the problems begin. The for each loop operates on every record in the collection at once rather than consecutively (admittedly my test data has thus far been limited to only two records in the collection reaching the second run), so all of the records get an email about a task assignment... But only the task linked in the last email sent exists when clicked. I am using an index variable in this loop so I've confirmed that it is running on both of them at once (with index=1 according to the logging for both instances).


So, tl;dr when my workflow ends and triggers itself again, the for loop therein runs simultaneously on the items in the collection rather than in order.


Is this a bug, a misunderstanding of functionality of the for loop, or an evil wizard, and what is the best way to resolve it?