For-Each
The For-Each statement allows you to easily cycle through elements in a list to perform the same actions on each element without having to create a loop within the workflow itself.
The For-Each statement is located under Common Statements in the Assets Panel.
After dragging a For-Each statement into the Builder area, you must specify two parameters:
-
List: The list that the for-each loop will cycle through. The list can be of a simple type (e.g. text, number, Boolean), a complex type (e.g. JSON object, Outlook mail item), or of a user-defined type. Once you have selected a list you may not change your selection.
-
Element name: The name of the temporary variable (iterator) that represents the element in the list corresponding to the current iteration of the loop. For example, the first time the loop executes, this variable represents the first element in the list, in the second iteration this variable represents the second element in the list, and so on.
This variable cannot be referenced outside of the for-each statement.
You cannot set the element name until you have specified the list to iterate.
Although you can use any name, it is recommended to use a meaningful name. For example, if your list is called ListOfNames, you might set the element name to name.
After specifying the element name and the list, add actions to the for-each loop and populate their parameters.
The Selector window that opens when you click to populate a function's parameter lists the element name (iterator) you specified for the for-each loop under More Options on condition that:
-
The list type matches the type required for that parameter.
-
The parameter is used to specify a value to read. You cannot write to the iterator. For example, you cannot assign a value to the iterator to change the value of the element in the list.
Example
The workflow below converts a list of names to lowercase.
The workflow performs the following steps:
-
The names in the Excel column shown below are added to the list ListOfNames.
The values in ListOfNames are visible in Execution mode.
-
Each element is read from the list and its lowercase equivalent is added to the list LowerCaseNames.
The values in LowerCaseNames are visible in Execution mode.