Out of the box SharePoint Designer Workflows do not have the capability of For Each loop hence the title here is misleading. However, you may run into situations where you will need to update multiple items in a list with a single action. The following steps will demonstrate how to perform updates to all items in a child list like a For Each loop. First, create a new list and name it “Parent List” and add three new items. The list should look like below:
Second, create a new library and name it “Child Document Library”. Add two new columns: ParentId and Processed. List information below:
Add several documents to this library and update each of the document properties:
You may have figured that our goal is to loop through All items in Child Document Library and update Processed column to Yes when an item is updated in Parent List. To accomplish this we need to setup a third list which will act a loop controller. So, create a new list and name it “Loop Controller”. Create two columns in this list: Last Item Updated and ParentId.
Next steps are to create workflows now that we have all the list and libraries created. We will create 3 workflows each for the lists and library we just set up and name them Parent List Workflow, Child Document Library Workflow, and Loop Controller Workflow. The names suggest which list is associated with which workflow. But before we go further along, I would like describe how it works so you get an idea when we actually develop these workflows:
1. User updates an item in Parent List
2. On list item update, the system starts Parent List Workflow which finds and updates the first unprocessed item in Child Document Library
3. On first library item update the system starts Child Document Library Workflow which creates a new list item on Loop Controller list.
4. On new item creation the system starts Loop Controller Workflow which finds and updates the Second unprocessed item in Child Document Library
At this point the looping starts. Since we updated the second item in Child Document Library which by the way creates a second list item on Loop Controller list, it triggers the Loop Controller Workflow to start again to update the third item in Child Document Library list. So on and so forth – you get the idea.
Parent List Workflow
1. Launch the site in SharePoint Designer 2010
2. Create a new List Workflow on Parent List
3. Name it Parent List Workflow
4. Select “Update List Item” action using Action setting on the ribbon
5. Click “this list” url to open “Update List Item” dialogue.
6. Set Processed field to “Yes” on Child Document Library
7. Click “Yes” to the warning dialogue.
8. Save the workflow and click Workflow Settings on the ribbon.
9. Check start option to start the workflow manually and when an item is changed.
10. Click Publish on the ribbon to deploy the workflow.
Child Document Library Workflow
1. Create a new List Workflow on Child Document Library and name it Child Document Library Workflow
2. Select “Create List Item” action using Action setting on the ribbon
3. Click “this list” url to open “Create New List Item” dialogue.
Title field Value settings below:
5. Save and then set start option to start the workflow manually and when an item is changed. Finally, publish the workflow
Loop Controller Workflow
1. Create a new List Workflow on Loop Controller list and name it Loop Controller Workflow
2. Add an Update List Item action and click “this list” to bring up Update List Item dialogue
3. Set Processed field to “Yes” on Child Document Library
Also Loop Controller list workflow also completed adding total of 8 records for the 8 items we had in Child Document Library. Notice that the last item shows “Error Occurred” and that is because it could not find any more item to process to go further – we can ignore that error.