Split In Batches#
The Split In Batches node saves the original incoming data, and with each iteration, it returns a predefined amount of data. This node can be used to loop through the data.
Node Reference#
- Batch Size: The number of items to return with each call.
- Options
- Reset: If set to true, the node will reset.
Warning
n8n natively processes incoming items. You may not need the Split In Batches node in your workflow. To learn more about how n8n handles multiple items, refer to the documentation on Looping in n8n.
Example Usage#
This workflow allows you to read RSS feed from two different sources using the Split In Batches node. The Split in Batches node is needed in the workflow since the RSS Read node only processes the first item it receives. You can also find the workflow on n8n.io. This example usage workflow would use the following nodes. - Start - Function - Split In Batches - RSS Feed Read
The final workflow should look like the following image.
1. Start node#
The start node exists by default when you create a new workflow.
2. Function node#
- Paste the following JavaScript code snippet in the Function field.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
3. SplitInBatches node#
- Set the batch size to
1
in the Batch Size field. - Click on Execute Node to run the node.
4. RSS Read node#
- Click on the gears icon next to the URL field and click on Add Expression.
- Select the following in the Variable Selector section: Nodes > SplitInBatches > Output Data > JSON > url. You can also add the following expression:
{{$node["SplitInBatches"].json["url"]}}
. - Click on Execute Node to run the workflow.
FAQs#
How to identify that no items are left to be processed by the node?#
To identify if items are left to be processed by node use the following expression: {{$node["SplitInBatches"].context["noItemsLeft"]}}
. This expression returns a boolean value. If there is data yet to be processed, the expression will return false
, otherwise true
.
Refer to this workflow to try it out.
How to get the current running index of the node?#
To get the current running index of the node, use the following expression: {{$node["SplitInBatches"].context["currentRunIndex"];}}
.
Refer to this workflow to try it out.