Skip to main content

For Each

The "For Each" node sequentially processes each element in the input array. This node features two output ports. The flow proceeds from the top port with each iteration, and once all elements in the array have been processed, the flow then advances from the bottom port. For each iteration, the flow must return to the start of the "For Each" node. To achieve this, you can either directly connect the wires or utilize a Go To / Label pair.

For Each Crossed

Or you can use a Go to Node and a Label to return to the For Each node's input as below:

For Each with Go to

How It Works

  1. The node receives an input array and creates a unique loop scope identifier (__fs)
  2. For the first iteration, it extracts the first element (index 0) and assigns it to the "Current Item" variable
  3. The flow exits through the top port with the current item data
  4. The flow must loop back to the For Each node's input (using direct connection or Go To/Label)
  5. On each return, the node increments the index and processes the next array element
  6. This continues until all elements are processed
  7. After the last iteration, the flow exits through the bottom port
  8. The loop context is cleaned up and removed from memory
  9. If a Break node is encountered, the loop exits immediately via the bottom port

Requirements

  • Input must be a valid array (can be from message field or variable)
  • The flow must return to the For Each node's input for each iteration
  • Current Item and Current Index variable names must be unique within the message scope

Error Handling

Error CodeDescriptionCause
Core.Programming.ForEach.ErrOnCreateConfig parse errorInvalid node configuration during creation
Core.Programming.ForEach.OnMessageMessage parse errorInvalid message format received
Array retrieval errorsFailed to retrieve arrayInput array variable not found or invalid data type
Index setting errorsFailed to set indexCannot write current index to message object

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If the ContinueOnError property is true, no error is caught when the project is executed even if Catch node is used.

Options

  • Loop through object - Specifies the input array to iterate through.
  • Current Item - The current item name in the loop
  • Current Index - The current index of item in the input array

Usage Examples

Example 1: Process List of Files

Set Variable (files = ["doc1.pdf", "doc2.pdf", "doc3.pdf"])
└─ For Each (Loop: files, Item: currentFile, Index: fileIndex)
├─ [Top Port] Process File (currentFile)
│ └─ Debug (fileIndex and currentFile)
│ └─ Go To (Label: "ForEachStart")
└─ [Bottom Port] Log "All files processed"

Iterate through each file name in the array and process them sequentially.

Example 2: Extract Data from Web Tables

Browser: Get Table Data → tableRows
└─ For Each (Loop: tableRows, Item: row, Index: rowNumber)
├─ Extract Cell Values
│ └─ Save to Database
│ └─ [Return to For Each]
└─ Log "Table extraction complete"

Loop through each row of a scraped web table and save data to a database.

Example 3: Nested Loops for Matrix Processing

For Each (Loop: departments, Item: dept, Index: deptIdx)
├─ For Each (Loop: dept.employees, Item: employee, Index: empIdx)
│ ├─ Send Welcome Email (employee.email)
│ │ └─ [Return to Inner For Each]
│ └─ [Inner Loop Complete] → [Return to Outer For Each]
└─ [All Departments Complete] Log "Emails sent to all employees"

Use nested For Each loops to process a two-dimensional data structure.

Usage Notes

  • The flow must loop back to the For Each input - forgetting this will cause the loop to execute only once
  • The top port is used for iteration; the bottom port is only triggered when the loop completes
  • Each For Each node maintains its own independent loop context via a unique scope ID
  • Nested For Each loops are fully supported - each maintains separate iteration state
  • The current index is zero-based (starts at 0) and is logged as "iteration [1/n]" for readability
  • Empty arrays will immediately exit through the bottom port without executing the top port
  • Loop contexts are automatically cleaned up when the flow exits or completes

Tips

  • Use meaningful names for "Current Item" (e.g., "customer", "order", "record") to make flows readable
  • Enable "Current Index" to track progress, especially useful for debugging or pagination
  • For simple linear flows, use direct wire connections; for complex flows, use Go To/Label pairs
  • Place Debug nodes inside loops to inspect data at each iteration
  • Use the Break node to exit loops early when a condition is met (e.g., found target item)
  • The bottom port is perfect for cleanup operations or "all done" notifications
  • Consider batch processing: collect results in an array and process in bulk after the loop
  • Break - Exit the loop prematurely
  • Go To - Navigate back to the loop start
  • Label - Mark the loop entry point for Go To
  • Debug - Inspect iteration data
  • Switch - Conditional logic within loops