For Each action
updated 3 months ago
For Each actions performs an action (or a set of actions), actions included within ForEach border. For Each action enables you to step through lists and iterate through the data and process each information (row) individually.
The elements of a list can be referenced in the action(s) within border by creating and using a local variable (iterator).
To show how ForEach works, let's create a process that goes through each element of a list (list of contacts and email addresses) and sends emails out to each and one of them.
How to configure the For Each action?
Go to the Process Designers section and open a new or an existing process. Actions configuration can be performed once they are dragged and dropped on canvas.
Step 1: Drag the For Each action from Toolbar and drop it on canvas.
Step 2: From the Process Variables (X) panel, create a new process variable, called inputData with the following specs:
- type clientDetails (data model with 3 attributes: email, name, body - type string) ;
- set as Input
Step 3: For Each Properties Panel configuration
1. In List represents the list of items you want to iterate through. a list type variable. Select the inputData list from selector:
2. Action timeout (max 600 seconds) - maximum number of seconds this action will run; once expiration behaviour is met, the next action in the flow will start.
3. For Each item is the item in the list used for each iteration. You can create a local variable by manually entering a name for it. This local variable will be further used in the actions within ForEach. We will name it now "iterator":
Step 4: After releasing the For Each action on canvas (Step 1), you will notice that it expands by default (becoming a bordered area). All the actions inside this border will be executed for each item in list.
Within the border you can add any type of action from Toolbar like in any process flow, except for Start and Stop. There is already a Start icon indication from where the For Each action flow starts processing; you have to connect the first action to the Start icon and you cannot delete it.
Now you can start adding actions within the border. Drag an action from Toolbar and connect it to the Start icon within the border.
Step 5: Add Send Email action within border - click on it and the corresponding Properties Panel of the action will open.
In Send Email action configuration, use the iterator variable created to reference each element of the list:
Save, Validate and Run the process. Give values to the list:
Run the process.
The For Each action iterates through each of the values specified in the List variable and will send separate emails to each element in the list.
Tips & Tricks:
- In order to add more actions, you need to resize the border by dragging the bottom-right corner of the border. Add new actions from Toolbar within the border.
- Ensure the border is wide enough to accommodate the actions you want to drag within its area.
- Ensure there is enough space on the canvas to expand the ForEach border. You can move the actions placed on the canvas in order to create space to expand the border.