I'm creating a form in SharePoint using Person Group field with option to add multiple. In the Nintex workflow, for each of the employees defined in the Person Group field, I need to run Query User Profile to look up their manager and store it in a variable. It works when I have one employee defined, but when I have two or more, it only looks up the manager of the first employee. How can I use the "For Each" function in the workflow? I'm very new to Nintex!
Try splitting your person group value with regional expression action and saving result in collection variable and then iterate that collection with for each loop action and query profile like you did before.
Donatas is spot on in his recommendation. You first need to load your People Group field into a Collection variable. In my example below that is the Target collection defined in the For Each setup. "Store result in" will be the individual person set as a variable. Index is a variable to track the index count. The "Stop processing" is not necessary (nor is the index), but can assist if you need to force an exit from the loop.
After you have these defined, within the loop you should be able to action whatever you need to against the "Store result in" variable.
Hi, Joanna deSouza, if the suggestions above work out, please mark one as correct. It helps the Community. Thank you!
I know it's been three years but, I thought I might add to this thread a little in case anyone else has a similar question.
Use the Allow multiple selection person or group field in a regulate expression action. The field is separated by a semicolon ( so put that as your pattern, then use your person group field as the input text and store the results in a collection variable.
Then configure a "For Each" action using your new collection variable as the target collection and creating a string variable to store each employee in.
within the for each, do your user profile query with the string employee variable plopping the results into collection variables. (I'm looking up the employee ID's as well)
Create a Multi line of text field on your list and update that item with your results. Be sure to include the value of the field prior to adding the new result and add the semicolon between each.
If you need to add the leaders to another person or group field, set that field value with your muti line of text field value. ( you cant set a person or group field with a workflow collection or string variable, that's why it had to be done this way.)