For Each

8min
ο»Ώ

For Each action performs an action (or a set of actions) included within ForEach border. ForEach 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 the 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. Select the list to iterate through, i.e. inputData

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

Document image
ο»Ώ

2. Set the iterator name (you can name it iterator or row or entry etc).

For Each itemΒ represents 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
ο»Ώ

2. Action timeout - you can set the maximum number of seconds this action and its enclosing actions are allowed to run for; When time expires, the next iteration will stop the action. Setting the value to 0 means there is no timeout at all, allowing the action to run for an unlimited number of iterations.

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.Β 

The drag&drop of a "Stop" action within a ForEach loop is currently prohibited, as it would prematurely terminate the entire process after a single iteration. However, a forthcoming action called "Exit ForEach" is being developed specifically to address this need by allowing for a controlled exit from a ForEach loop.

ο»Ώ

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 the 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 16 Feb 2024
Doc contributor
Doc contributor
Did this page help you?