For Each action

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.

Document image

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) ;
  • List
  • set as Input
Document image

Step 3: For Each Properties Panel configuration.

Document image

1. In List represents the list of items you want to iterate through. Select from Process Variables selector a list type variable.  Select the inputData list from selector: 

Document image

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":

Document image

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.

Document image

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.

Document image

Step 5: Add the 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:

Document image

Step 6: Save, Validate and Run the process. Give values to the list:

Document image

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.

Updated 27 Apr 2022
Did this page help?