Loop Over Items
The Loop action iterates over an array and executes actions for each item. This is perfect for processing lists, bulk operations, and batch processing.Basic Loop Structure
1
Add a Loop Action
Click the + button and select Loop Over Items.
2
Configure Items Array
Set the items to loop over. This can be:
- Data from a previous step:
{{ get_data.body.results }} - A literal array:
{{ [1, 2, 3, 4, 5] }} - An expression:
{{ trigger.users.filter(u => u.active) }}
3
Add Actions Inside Loop
Click inside the loop to add actions that will execute for each item.
Loop Variables
Inside a loop, you have access to special variables:Loop Examples
- Send Bulk Emails
- Process Orders
- Transform Data
Loop over a list of users and send each one an email:
Loop Output
When a loop completes, it produces an output with all iterations:You can access loop results in subsequent steps using
{{ loop_name.output.iterations }}Conditional Branches (Router)
The Router action lets you create conditional branches in your workflow, executing different actions based on conditions.Router Structure
1
Add Router Action
Click the + button and select Router (or Branch).
2
Configure Conditions
Set up conditions that determine which branch to execute.
3
Add Branch Actions
Add actions to each branch path.
Branch Operators
Activepieces supports many condition operators:Text Operators
- Contains
- Does not contain
- Exactly matches
- Starts with
- Ends with
Number Operators
- Equal to
- Greater than
- Less than
Boolean Operators
- Is true
- Is false
Existence Operators
- Exists
- Does not exist
Branch Operators Reference
Execution Types
- Execute First Match
- Execute All Match
Execute only the first branch whose condition is true:Use this when you want if-else behavior.
Branch Examples
- Status-Based Routing
- Number-Based Routing
- Multiple Conditions
- Existence Check
Route based on order status:
Router Output
Combining Loops and Branches
You can nest loops inside branches and vice versa:Loop with Conditional Logic
Branch with Loops
Skipping Control Flow
You can skip loops and routers conditionally:Error Handling in Control Flow
Loop Error Handling
Best Practices
Limit Loop Iterations
Limit Loop Iterations
Be mindful of loop size. Processing 1000+ items can take time and consume resources.
Use Meaningful Branch Names
Use Meaningful Branch Names
Name your router actions to describe the decision being made:
Test Edge Cases
Test Edge Cases
Test your control flow with:
- Empty arrays for loops
- Null/undefined values in conditions
- Both branches of routers
Keep Branches Simple
Keep Branches Simple
If branches become complex, consider splitting into separate flows and using subflows.
Document Complex Logic
Document Complex Logic
Use notes to explain why certain branches or loops exist.
Common Patterns
Filter-Then-Loop
Priority-Based Routing
Next Steps
Error Handling
Handle errors in loops and branches
Passing Data
Learn more about data flow
Debugging
Debug control flow issues
Best Practices
Optimize your workflows