Loop Over Items
The Loop Over Items node enables you to iterate through data when required.
The node preserves the original incoming data and returns a predefined amount of data through the loop output with each iteration.
Upon completion, the node consolidates all processed data and returns it through the done output.
When to use the Loop Over Items node
By default, nodes process lists of input items automatically (with some exceptions detailed below). Depending on your requirements, you often don't need the Loop Over Items node in your workflow.
These resources highlight scenarios where the Loop Over Items node proves useful:
- Loop until all items are processed: explains how the Loop Over Items node differs from standard item processing and when to incorporate it.
- Node exceptions: describes specific cases and nodes where you need to implement manual looping logic using the Loop Over Items node.
- Avoiding rate limiting: demonstrates how to batch API requests to prevent rate limits from external services.
Node parameters
Batch Size
Specifies the number of items to return with each iteration.
Node options
Reset
When enabled, the node reinitializes with the current input data at each loop iteration. Use this option when you want the Loop Over Items node to treat incoming data as a new dataset rather than a continuation of previous items.
For example, you can combine the Loop Over Items node with the reset option and an If node to query paginated services when the total page count is unknown. The loop queries pages sequentially, processes the data, and increments the page number. The reset functionality ensures each iteration recognizes the data as new. The If node evaluates an exit condition to determine whether to continue iterating.
For workflows implementing this pattern, you must include a valid termination condition. Without a proper termination condition, your workflow will enter an infinite loop.
When enabled, you can customize reset conditions by changing the parameter representation from Fixed to Expression. The expression's evaluation result determines when the node resets item processing.
Templates and examples
This workflow demonstrates reading RSS feeds from two different sources using the Loop Over Items node. The Loop Over Items node is necessary because the RSS Feed Read node only processes the first item it receives. You can also find the workflow.
This example guides you through building the workflow, assuming familiarity with basic concepts. For your first workflow, including node addition instructions, refer to Try it out.
- Add the manual trigger.
- Add the Code node.
- Copy this code into the Code node:javascriptreturn [ { json: { url: "https://medium.com/feed/@fmzquant", }, }, { json: { url: "https://dev.to/feed/googlecloud", }, }, ];
- Add the Loop Over Items node.
- Configure Loop Over Items: set the Batch Size field to
1. - Add the RSS Feed Read node.
- Select Execute Workflow to run the workflow and load data into the RSS Feed Read node.
- Configure RSS Feed Read: map
urlfrom the input to the URL field. You can drag and drop from the INPUT panel or use this expression:{{ $json.url }}. - Select Execute Workflow to run the workflow and view the results.
Check whether the node has processed all items
To verify if the node has remaining items to process, use the following expression: {{$node["Loop Over Items"].context["noItemsLeft"]}}. This expression returns a boolean value: false if items remain, true if processing is complete.
Get the current running index of the node
To retrieve the current iteration index, use the following expression: {{$node["Loop Over Items"].context["currentRunIndex"];}}.