ForEach node
The ForEach node allows executing a sequence of nodes for each element of an array.
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| Array | Array | ✅ | — | Array to iterate over with the loop. |
| Iteration variable | String | ❌ | item | Name of the variable representing the current element. |
| Batch size | Number or variable | ❌ | — | Number of elements processed per batch, as a fixed value or a variable (dictionary, context). |
| Batch processing | Option | ✅ | 1 | Iterate over the array by splitting it into batches. Each batch size defaults to 1. |
Array
Specify the array to iterate over:
- Context variable:
{{items}} - Object property:
{{order.items}} - Result of a previous node:
{{lastResponse.data.results}}
In simple mode, the Iterate on Which Array field New accepts the reference with or without double braces (context.orders or {{context.orders}}). Handlebars highlighting is shown in both cases.
Iteration variable
Name of the variable that will contain the current element:
- Default:
item - Can be customized:
orderItem,product, etc. - Accessible in the following nodes:
{{item}}or{{orderItem}}
Batch size
The batch size can be defined by a variable rather than a fixed value:
- Fixed value:
50 - Context variable:
{{context.batchSize}} - Dictionary variable:
{{dictionaries.config.batchSize}}— the value is then dynamized according to the environment
Batch processing
Option allowing to iterate over the array by splitting it into batches:
- Useful to process large amounts of data
- Allows managing the processing load
- Configure the batch size according to your needs
Input
The node receives an array from the workflow context and iterates over it element by element. For each element:
- The iteration variable is set
- The following nodes are executed
- The context is updated
The loop continues until all the elements are processed.
Output
The node sets the iteration variable in the context for each processed element; the following nodes access it with {{item}} (or the customized name). The parent context data remains accessible.
For a loop over {{resultats_db}} with an iteration variable client, each turn exposes the current element:
{
"client": { "id": 1, "email": "user1@example.com", "created_at": "2023-01-01" }
}
Inside the loop, access the element's fields via {{client.email}} (or {{item.email}} with the default name). The rest of the context — trigger data, parent variables — remains accessible.
Errors
A failing iteration can block the rest of the processing. Handle errors with an On Error node.
Limits
- Process lists of homogeneous objects: each iteration applies the same node sequence, so prepare a coherent object structure upstream (Code node or extractors).
- Avoid overly heavy loops: each iteration consumes execution time, and a very large list or slow API calls per iteration can reach the environment timeout.
- Prefer batch processing for large volumes, and limit the expensive operations (HTTP calls, SQL requests) inside the loop.
Example
The node is used to:
- Process each element of an array
- Apply the same logic to several elements
- Iterate over data collections
- Perform loop operations
Example 1: Process orders
Configuration:
- Array:
{{orders}} - Variable:
order
Result:
- Each order is processed individually
{{order}}contains the current order
Example 2: Send emails
Configuration:
- Array:
{{users}} - Variable:
user
Workflow:
- ForEach on
{{users}} - Send an email node with
{{user.email}} - Each user receives an email
Example 3: Multiple API calls
Configuration:
- Array:
{{productIds}} - Variable:
productId
Workflow:
- ForEach on
{{productIds}} - HTTP(S) request to
/api/products/{{productId}} - Processing of each product
For loops over large arrays, split into batches and handle errors with an On Error node: a failing iteration can block the rest of the processing.