Skip to main content

ForEach node

The ForEach node allows executing a sequence of nodes for each element of an array.

Parameters​

ParameterTypeRequiredDefaultDescription
ArrayArray✅—Array to iterate over with the loop.
Iteration variableString❌itemName of the variable representing the current element.
Batch sizeNumber or variable❌—Number of elements processed per batch, as a fixed value or a variable (dictionary, context).
Batch processingOption✅1Iterate 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:

  1. ForEach on {{users}}
  2. Send an email node with {{user.email}}
  3. Each user receives an email

Example 3: Multiple API calls​

Configuration:

  • Array: {{productIds}}
  • Variable: productId

Workflow:

  1. ForEach on {{productIds}}
  2. HTTP(S) request to /api/products/{{productId}}
  3. Processing of each product
Avoid infinite loops

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.

See also​