Loop
The Loop node enables iteration through collections (arrays) in workflows, allowing you to process each item individually and optionally collect results into a new output collection. This is essential for handling multiple records, batch processing, and transforming datasets in logistics operations.
Overview
The Loop node is essential when you need to:
- Process multiple records - Handle arrays of shipments, invoices, or tracking updates
- Batch operations - Perform the same action on multiple items
- Data transformation - Convert each item in a collection to a new format
- Filtering and validation - Process items and collect only those that meet criteria
- API calls for each item - Make individual requests for each record in a dataset
- Aggregation - Collect and combine results from processing multiple items
Configuration
Input Collection
- Collection source - Array of items to iterate through (from previous workflow nodes)
Loop Body
The workflow steps that execute for each item in the collection:
- Processing nodes - Any combination of Splice nodes to process each item
- Conditional logic - Use If nodes to handle different item types
- External calls - Make API requests or database queries for each item
Result Collection (Optional)
- Result variable - Map a value from the loop body to collect into output array
- Output transformation - Define what data to extract from each iteration
Loop Execution
Sequential Processing
- Items are processed one at a time in order
- Each iteration has access to the current item
- Loop body executes completely before moving to the next item
- Results are collected in the same order as input items
Variable Scope
- Item variable - Contains the current item being processed
- Result variable - Collected into the output array
Example Usage
Simple Data Transformation
Input: Array of shipment objects
Item Variable: shipment
Loop Body:
- Transform shipment data to standard format
Result Variable: transformedShipment
Output: Array of transformed shipments
API Calls for Each Item
Input: Array of tracking numbers
Item Variable: trackingNumber
Loop Body:
- HTTP Request to carrier API with trackingNumber
- Extract status from API response
Result Variable: trackingStatus
Output: Array of tracking statuses
Conditional Processing
Input: Array of invoices
Item Variable: invoice
Loop Body:
- If invoice.amount > 10000:
- Send for approval
- Set status to "pending_approval"
- Else:
- Auto-approve
- Set status to "approved"
Result Variable: processedInvoice
Output: Array of processed invoices with updated status
Data Enrichment
Input: Array of customer IDs
Item Variable: customerId
Loop Body:
- HTTP Request to CRM API to get customer details
- Code node to calculate customer tier
- Combine original ID with enriched data
Result Variable: enrichedCustomer
Output: Array of customer objects with full details
Filtering and Validation
Input: Array of shipment records
Item Variable: shipment
Loop Body:
- Validate shipment data completeness
- If valid:
- Format for export
- Return formatted shipment
- If invalid:
- Log error
- Return null (filtered out)
Result Variable: validShipment (only when not null)
Output: Array of valid, formatted shipments
Advanced Patterns
Nested Data Processing
Input: Array of orders (each with line items)
Item Variable: order
Loop Body:
- Inner Loop through order.lineItems
- Calculate item total
- Check inventory
- Sum all item totals for order total
Result Variable: processedOrder
Output: Array of orders with calculated totals
Batch API Calls with Rate Limiting
Input: Array of tracking requests
Item Variable: request
Loop Body:
- HTTP Request to tracking API
- If rate limited (429 response):
- Wait 1 second
- Retry request
- Extract tracking data
Result Variable: trackingData
Output: Array of tracking information
Aggregation and Reporting
Input: Array of daily sales records
Item Variable: salesRecord
Loop Body:
- Code node to extract metrics
- Calculate daily totals
- Determine top products
Result Variable: dailyMetrics
Output: Array of processed daily metrics for reporting
Best Practices
Performance Optimization
- Limit collection size - Process large datasets in smaller batches
- Minimize external calls - Batch API requests when possible
- Efficient processing - Keep loop body operations lightweight
Error Handling
- Handle item failures - Use try/catch patterns to continue processing other items
- Validate input data - Check that input is actually an array
- Default values - Provide fallbacks for missing or invalid item data
- Error collection - Track which items failed processing
Data Management
- Memory usage - Be mindful of large collections and result sizes
- Result filtering - Only collect necessary data in result variable
- Data types - Ensure consistent data types in result collections
- Null handling - Decide how to handle null or undefined results
Common Use Cases
Shipment Status Updates
Process multiple tracking numbers to get current status:
TrackingNumbers → Loop → API Call per Number → Collect Statuses → Update Database
Invoice Processing
Validate and process multiple invoices:
Invoices → Loop → Validate → Calculate Totals → Collect Results → Generate Report
Customer Notifications
Send personalized notifications to multiple customers:
Customers → Loop → Personalize Message → Send Email → Collect Delivery Status
Data Migration
Transform records from one system format to another:
OldFormat → Loop → Transform Structure → Validate → Collect NewFormat → Import
Troubleshooting
Common Issues
- Not an array - Ensure input collection is actually an array
- Empty results - Check if result variable is being set correctly
- Memory errors - Reduce collection size or result data
Debugging Tips
- Check collection size - Verify input array length
- Test with small datasets - Start with a few items before processing large collections
The Loop node is fundamental for processing collections in logistics workflows, enabling efficient batch operations and data transformation at scale.