For Each
Iterate over an array of strings and execute downstream nodes once for each item
Node Type
Control Flow
Category
Loop
Icon
Repeat
Overview
The For Each node is a control flow node that takes an array of strings and causes the workflow to iterate over each item, executing downstream nodes separately for every value. This powerful looping mechanism allows you to process multiple items in sequence, making your workflows more dynamic and efficient.
Key Features
- • Array Iteration: Processes each item in an array sequentially
- • Downstream Execution: Executes connected nodes for each array item
- • Item Access: Provides current item and index to downstream nodes
- • Flexible Input: Accepts comma-separated lists or JSON arrays
- • Loop Control: Manages workflow execution flow for repetitive tasks
- • Data Processing: Enables batch processing of multiple data items
Prerequisites
Array Data Source
Must have an array of strings to iterate over
Downstream Nodes
Technical Requirements
Node Configuration
Required Fields
Array
An array of strings to iterate over. Can be provided as a comma-separated list or JSON array format. The node will parse this input and execute downstream nodes for each item in the array.
Technical Details
Loop Execution Process
How the node manages workflow iteration and execution
Initial Execution
The For Each node executes once initially, providing the first item and index:
- • Items: Returns the complete input array
- • Item: Returns the first item (array[0])
- • Index: Returns 0 (first position)
Loop Control
The workflow engine uses the isForLoop
flag on the Items output to recognize this as a loop node and automatically iterate over the array.
Array Input Processing
How the node handles different array input formats
Input Parsing
The node accepts input as ARRAY_JSON
type, which means it can handle both JSON array format and comma-separated string lists that get converted to arrays.
Data Validation
Ensures the input is a valid array and provides fallback values for the initial execution. The actual loop iteration is managed by the workflow engine.
Type Safety
Uses TypeScript generics to ensure type safety when parsing the array input, making the node robust and predictable in its behavior.
Workflow Engine Integration
How the node integrates with the workflow execution system
Loop Recognition
The isForLoop
flag on the Items output signals to the workflow engine that this node should trigger loop execution.
Downstream Execution
For each array item, the workflow engine automatically executes all downstream nodes with the updated Item and Index values, creating a complete iteration cycle.
Context Management
Each iteration maintains its own execution context, allowing downstream nodes to access the current item and index values independently.
Examples & Use Cases
Basic Array Iteration
Iterate over a simple list of items
{
"array": ["apple", "banana", "orange", "grape"]
}
This will execute downstream nodes four times, once for each fruit. Each iteration will haveitem
set to the current fruit andindex
set to 0, 1, 2, and 3 respectively.
Comma-Separated Input
Use comma-separated values as input
{
"array": "red,blue,green,yellow,purple"
}
The node will automatically parse the comma-separated string into an array and iterate over each color. This format is useful when working with simple lists or user input.
Dynamic Array from Workflow
Use array data from previous workflow steps
{
"array": "{{previousNode.outputArray}}"
}
Uses template syntax to reference an array output from a previous node. The For Each node will iterate over whatever array is provided by the upstream node.
Workflow Examples
Batch Email Processing
Send personalized emails to multiple recipients
Workflow Structure
For Each Configuration
{
"array": "{{emailListNode.emailAddresses}}"
}
Implementation Steps
- Email List: Provides array of email addresses
- For Each: Iterates over each email address
- Email Template: Creates personalized email content
- Send Email: Sends email to current recipient
- Log Result: Records success/failure for each email
Data Processing Pipeline
Process multiple data files or records
Use Case
Automatically process multiple data files, records, or items by iterating over a list and applying the same processing logic to each item individually.
For Each Configuration
{
"array": "{{fileListNode.fileNames}}"
}
Processing Steps
- File list provides array of file names to process
- For Each iterates over each file name
- File processing logic executes for current file
- Results are collected and logged for each file
- Process continues until all files are processed
Best Practices
Do's
- • Use meaningful array names that describe the data being processed
- • Ensure downstream nodes can handle the Item and Index outputs
- • Test with small arrays first before scaling to large datasets
- • Use the Index output for conditional logic or tracking
- • Consider array size and potential execution time
- • Validate array input data before processing
- • Use template syntax for dynamic array sources
Don'ts
- • Don't use extremely large arrays that could cause timeouts
- • Avoid nested loops unless absolutely necessary
- • Don't forget to handle empty arrays in downstream nodes
- • Avoid modifying the array during iteration
- • Don't assume array items are always strings
- • Avoid hardcoding array values when dynamic sources are available
- • Don't ignore the loop execution context
Troubleshooting
Common Issues
Empty Array Input
Symptoms: Node executes but no downstream nodes run
Solution: Verify the array input contains data. Check upstream nodes that provide the array data and ensure they're generating valid arrays.
Downstream Nodes Not Executing
Symptoms: For Each node runs but connected nodes don't execute
Solution: Ensure downstream nodes are properly connected. Check that the workflow engine supports loop execution and loop nodes are properly configured.
Array Parsing Errors
Symptoms: Node fails to parse array input or returns errors
Solution: Verify the input format is valid. Use proper JSON array syntax or ensure comma-separated values are properly formatted.
Infinite Loops
Symptoms: Workflow gets stuck in endless iteration
Solution: Check that the array input is not being modified during iteration. Ensure downstream nodes don't accidentally change the array being processed.