cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

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

Jump to solution

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!

Labels: (1)
Reply
19 Replies
melissac
Nintex Newbie

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

Jump to solution

@Kevin

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.

0 Kudos
Reply
powersj1
Nintex Newbie

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

Jump to solution

Can you send over workflow screenshots?  Some pictures may make it easier to follow.

0 Kudos
Reply
Not applicable

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

Jump to solution

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..

0 Kudos
Reply
Not applicable

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

Jump to solution

Added the workflow and the workflow history.

0 Kudos
Reply
melissac
Nintex Newbie

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

Jump to solution

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.

0 Kudos
Reply
Not applicable

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

Jump to solution

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.

0 Kudos
Reply
ghkrause
Nintex Newbie

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

Jump to solution

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.

0 Kudos
Reply
Not applicable

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

Jump to solution

I added the screens you wanted, it's always the second Iteration..

0 Kudos
Reply
Not applicable

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

Jump to solution

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.

0 Kudos
Reply