Loop
Use the Loop action to execute an action or a set of actions repeatedly for a given number of times or until a specified condition is met.
Complete the following steps to use the Loop action in your workflow:
Part A: Configure the Loop action
1. Click and drag the Loop action under Loop to the canvas. The Loop block is displayed on the canvas.
2. Place the pointer on the action, and then click or double-click the action. The Loop window opens.
3. Edit the Label, if needed. By default, the label name is the same as the action name.
4. In the Select Loop Type field, select one of the following options, and perform its respective task:
Select Loop Type
Task
Times—Repeats a task or multiple tasks until the specified count is met.
It is recommended that you select this option when the workflow within the Loop action does not require any input from the previous action.
An example of the Times loop is available here.
In the Number of Times field, specify the number of times that the loop should execute.
Each Item—Repeats a task or multiple tasks for each item in an array or a collection.
An example of the Each Item loop is available here.
In the Source Array or Object field, map the output of a previous action to provide an array or object.
While—Repeats a task or multiple tasks until the specified condition is met.
An example of the While loop is available here.
a. In the Initial Value field, provide the initial value for the loop. This can be a number, boolean, string, or JSON.
This value sets the $currentItem value. This value is used only once before the loop starts.
b. In the Condition field, provide the condition. If you want to use an item from Initial Value, use $currentItem in the inline expression. For example: {{$currentItem}} < 5.
This condition is evaluated each time before a loop is executed. If the result of this condition evaluates to true, the loop continues; otherwise, the loop breaks. Setting Condition to 0, false (case-insensitive), or leaving it empty evaluates the condition to false and breaks the loop.
* 
If the condition is true infinitely, then the loop runs until the workflow times out. The default workflow timeout is 3 minutes.
c. In the Updated Value field, provide the updated value. This can be a number, boolean, string, or JSON.
This value updates the $currentItem value. This expression is evaluated once after every loop cycle.
* 
For the Updated Value field, you can use the output of any actions within the loop. However, since the output of the actions within the loop is not shown, you need to manually map the output by referring to the action index.
For Initial Value and Condition, if you use the output of any action within the loop, the Condition evaluates to undefined, and the Loop fails.
5. Click Done.
6. Additionally, hover over the Loop block to perform the following tasks:
Click to maximize or minimize the Loop block.
Click to remove the Loop block from the canvas.
Part B: Adding actions outside the Loop block
1. On the right side of the Workflow Editor, from the ACTIONS panel, drag the actions to the canvas outside the Loop block.
You can have one or more actions before and after the Loop block.
2. Connect the action preceding the Loop block to .
3. Connect the action following the Loop block to .
4. Configure the actions per your requirement.
Part C: Adding actions to the Loop block
1. On the right side of the Workflow Editor, from the ACTIONS panel, drag an action onto the Loop block. The Loop block is highlighted when the action is on the Loop block. After you drop the action on to the Loop block, and if it is the first action in the block, the action is automatically connected to .
You can add a single action or multiple actions into the Loop block.
Once you drag an action to the canvas outside the Loop block, you cannot drag it inside the Loop block.
2. Add multiple actions to the Loop block and connect them one after the other. If you want, you can have only one action inside the Loop block.
3. Connect the last action in the Loop block to .
4. Configure the actions in the Loop block per your requirement.
Execution
When a workflow is executed, it starts with the first action in the workflow, executes all actions within the loop block repeatedly until the defined count or condition is met, and then subsequently proceeds to the following actions.
Output schema
For Times loop:
currentIndex—Index or the position of the current iteration, starting with 1.
currentKey—Index or the position of the current iteration, starting with 0.
currentItem, currentValue—Current value of the iteration.
totalLength—Number of times loop is iterated..
For Each Item loop:
currentIndex—Index or the position of the current iteration, starting with 0.
currentItem—If the source is an object, the property returns the value corresponding to currentIndex. If the source is an array, this property returns the current object for each iteration.
currentKey—If the source is an object, this property returns the keys of the object. If the source is an array, it returns the index of every item.
currentValue—If the source is an object, this property returns the values of the object. If the source is an array, it returns all the items of the array, including objects, if any, within the array. To retrieve the value of a particular key or property, specify {{$ActionID.currentValue.<PropertyName>}}
totalLength—The total count of all objects within an array of objects, or the total count of all items within an array.
For While loop:
currentIndex, currentKey—Index or the position of the current iteration, starting with 0.
currentItem, currentValue—Returns the current value of the iteration.
totalLength—Undefined.
Was this helpful?