I'm trying to do a list query within a for each loop. Sounds quite easy and it does work during the first iteration, but I simply don't understand why it breaks when the for each continues with the second value. To give you some background information: I'm using SharePoint 2010 with Nintex 2010.
I have three lists: List A with dashboards, List B, where users (stored as Lookup from another List, not as person/group) are connected to the dashboards from list A (dashboards from list A stored as Lookup) and List C, where during item creation one or more dashboards from list A can be selected.
The objective of my workflow is, to get all users connected to the dashboards selected in List C.
Thats it. Each time when I choose only one dashboard in List C, everything works totally fine. But as soon as I choose more than one dashboard and the second iteration within the first for each begins, the temporary user collection is empty and therefore, no users are added to the main user collection. For some reason the query list in the for each loop does only work during the first iteration. I already checked, the for each itself works, the current dashboards changes.
So I tried it hardcoded, added dashboards to a collection via collection operation (In the collection operation I did a list lookup and compared to my hardcoded string name of the dashboard.) and used the same for each loop with list query etc. I only changed the input. It worked perfectly fine! But not, when I get the data from the lookup values. Whereas, it does work, but only during the first iteration?!
It would be great if somebody could support me with this issue!
Solved! Go to Solution.
Do you think you could post a screen of the WF, so that we can take a look at it?
Not Sure if this helps But in the For each you In the "Target Collection" you are adding your collection variable and then in "Store Result in" a List Variable and then add a Query List inside the For each that filters out those items.
I added the workflow and the workflow history. From the history you can see, that the current Dashboard has changed, but the temporary user collection is empty after the second Iteration.. Consequently, the for each works as intended..
Are the functions running in the " For Each"? I also put my variables in "Log History" so that I can see if it's collecting any data you may want to do that just to make sure it's getting data.
I log the current dashboard (the one which is currently set by the "for each") and the temporary user collection (the one which shall be set by the query list). The log shows, that the current dashboard changes, but the temporary user collection is empty during the second Iteration, although the current dashboard is set correctly. The "for each" within the "for each", which is responsible for saving the users from the temporary user collection into the main user collection works. Therefore, it's always filled with the users from the first dashboard.
We do not know the content of the lists. So I kindly ask you to send workflow history screenshot for
a) "Testdashboard_2" (only)
b) First "Testdashboard_2" and then "Testdashboard"
Maybe there is no person for Testdashboard_2?
TIP: I always enter label information for each step in the workflow to reduce guessing what happens in each box. Of course, if that information is not maintained and might get inconsistent to the step itelf then it is not worth a penny.
When I've populated a collection variable inside of a For Each, I've found that the second time through the loop, it appends the results from the second round on to what was already there for the first round.
Just after the close of your second ForEach, you should put in another Collection Operation action. That action needs to empty the collection that is populated by your Query List operation.