As mentioned in the Bamboo product documentation for Workflow Conductor, the Repeat For Each Item widget executes a sequence of other widgets for each item in a list. The widget can repeat this sequence once for every item in a list, or it can be limited to a specific start and end item and/or a specific list view. You can drop any combination of widgets into the Repeat For Each Item widget. In this example, we’ll simply be using the Log History widget in the Repeat For Each Item widget in order to create the following workflow.
First, you will need to configure the Repeat Item for Each widget:
- Configure the repeat settings: Click the button to select the items which will be cycled through in your loop. Please note that if you do not make any selections, the loop will start with the first item in the list and continue in order (by SharePoint ID) to the last item in the list:
If you prefer to limit your workflow to a specific start or end item, select and Conditional Item option and configure a lookup to determine which item in the list be your start or end item. For the purposes of this example, we will leave this set to First Item of List and Last Item of List.
Next, click the Create new variable link next to the variable list. This variable will be used to store the ID of the item that is currently selected in the loop. In this example, all of the item IDs will be used in the Log History widget:
After clicking Create a new variable, a new form will pop up from which you can create your new variable. After you have created the new variable, click Save Changes to add the new variable to the workflow:
Next, click the Apply button to save the configuration for the Repeat For Each Item widget:
Next, configure the Log History widget to reference the Current Item: Title field (pictured below) by opening the Outcome property, using the Add Lookup button, then selecting Title from the Current Item. Please note that the Current Item refers to the item the workflow was started on. It does NOT refer to the item that the Repeat For Each Item widget is currently on in the loop:
After the above steps have been completed, run the workflow. In our example, you can see that the workflow was started on an item titled “test 03”:
When the workflow runs, it will grab the title of the current item on which the workflow is being run, and populate the Outcome field in a new history log. In this example, the title of the current item is “test 03” and we set out a loop to run from the first item to the last item, so you will see a new history log entry for every item in the list, and they will all have an Outcome value of “test 03”, since that is the value of the title field for the item on which the workflow was started (Current Item).
If we want to get a value from the current loop item rather than the current workflow item, we would need to configure things differently. For example, to get the Title value of every item in the list, here is how the Log History widget would be configured:
Use a field lookup that returns Title by getting the item where the ID of the item is equal to the variable we created earlier to store the current Loop Item ID.
{Variable: repeat}: Variable was created from the Repeat For Each Item widget.
When the workflow runs, it does a lookup for each item it loops through that will get the Title value of that item and write it to the history log.
Consequently, the results will be as follows:
In summary, to reference the item on which the workflow is run, use Current Item. To reference a field value in the loop item, use a field lookup to the current list that gets the right item by matching the Item ID to the Loop Item ID stored in the variable selected in the widget settings.
Questions? Contact us!