AnsweredAssumed Answered

How can I do a list query within a for each loop?

Question asked by kevinfrey on Nov 10, 2015
Latest reply on Oct 17, 2016 by scalawagd

Hello,

 

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.

 

  1. Firstly, I need to save all dashboards selected from the latest item. I’m using a regular expression, to store all selected dashboards from List A into a collection variable.
  2. Then I do a for each and loop trough each dashboard saved in the collection variable:
    1. Within this for each loop, I do a list query over List B, to get all users connected to the current dashboard in List B and save them into a temporary user collection.
    2. Then I do a for each loop, where each item from the temporary user collection is stored in the main user collection via a collection operation

 

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!

Outcomes