I'm trying to create a workflow that will loop through the items in a list using a For Each loop and send a Request for Approval to each of the emails (People and Groups) (one per item) . The workflow grabs the first item in the list but doesn't move on to the next item. Is there a way to set up the workflow to send to all of the records/emails in the list? Currently the workflow
1) calculates a date
2) queries the list for items that have expired
3) for each item
a) sets a variable for the individual email address
b) request approval sets the approver using the email variable
c) updates the list item once approved
d) sends an email to the declined user if not approved.
Solved! Go to Solution.
In the example workflow that you provided, is there a reason that you are using a Run Parallel action to cycle through the same collection, using the same variables on each branch? This could cause concurrency issues; one branch changing your current item ID before it is fully finished executing the other branch, and thereby causing this failure to proceed through the foreach loop. Remove the parallel action and try giving it a run.
When I need to loop through multiple docs in a library (/items in a list),
I normally split this into 2 workflows: a list workflow and a site workflow.
The is first workflow is configured on the list/library.
This workflow would be the approval workflow for the individual item.
Having a look through your workflow export, I would typically use a Request flexi task rather than a Request approval action as that has more options, reminders, etc.
This makes this workflow a little more simple to manage and you have the advantage of a workflow status column to track the workflow on an individual item.
On another note If you have content approval turned on the in the version settings, I might also look to have the flexi task and the set approval status actions within an action set. Then the action set in the common properties can be configured to run as the workflow owner and thus get around any permission issues.
The second workflow I create as a site workflow.
This workflow runs a query list (which you could add a filter if you don't want all the items).
Output to a collection variable.
Then add for each to process the collection variable into a variable of type 'list item ID'.
The for each loop then runs the Call web service action.
Follow the following guide on how to call the list workflow that you created earlier for each item.
You can then use a schedule to call the site workflow either as a once off or on a regular schedule.
Be sure to use a non system account user to start it or otherwise you might run into some problems with starting declarative workflows.
Hope this helps.
I have a follow-up question to this and I'm not sure if I should start a new thread, but here goes...
The list is rather large and I want to send an email reminder to each Manager (Person or Group field) on the list, but don't want to send them an email for every single record (one Manager might have hundreds of records and need only receive one email reminder to come to the site to complete the approval for their set of records.) Is there a way to loop through the list and get one record for each distinct Manager on the list before sending the email?