Split In Batches: currentRunIndex Loop Control Example
Demonstrates using `currentRunIndex` in n8n's Split In Batches node to precisely control batch loops, breaking after 5 iterations on single-item batches.
This workflow showcases how to leverage the currentRunIndex property in the Split In Batches node for fine-grained loop control in n8n. It starts with a manual trigger, generates 10 mock data items via a Function node, then splits them into batches of size 1. The IF node checks if the current run index equals 5 using the expression {{$node["SplitInBatches"].context["currentRunIndex"]}}, routing to break the loop when true, or continue processing otherwise. A final Set node outputs 'Loop Ended' once the condition is met.
Key to this example is accessing the hidden context variable currentRunIndex, which tracks the current batch iteration (starting from 0). This enables dynamic loop termination without processing all items, ideal for scenarios needing conditional batching. The workflow loops exactly 5 times before exiting, demonstrating efficient data handling.
Benefits include reduced execution time by avoiding unnecessary iterations, better resource management for large datasets, and customizable batch logic. Use cases: API rate limiting (stop after X calls), data validation loops (halt on error threshold), paginated exports (process until limit), or testing batch-dependent nodes. Easily adapt by replacing the Function with your data source and adjusting batch size or IF condition.
As a development tool, it's perfect for learning n8n's looping mechanics, debugging batch flows, or templating production automations in IT/dev environments.
New buyers can create an account from the cart to unlock a controlled $10 first-purchase credit on eligible orders of $25+.
Related bundle
WhatsApp Business Automation
7 workflows for $39.00 (save 52%).
$82.94 if bought separately.
View bundleSecure checkout powered by Stripe
Support
How to import this workflow into n8n
- 1Purchase or download the workflow to get the n8n workflow JSON file.
- 2In your n8n instance, open Workflows and choose "Import from File" (or paste the JSON with Ctrl+V on the canvas).
- 3Open each node marked with a credential warning and connect your own accounts and API keys.
- 4Run the workflow once manually to verify the data flow, then toggle it to Active.
Related Personal workflows
- SEO Data Analyst Workflow for E-commerce Insights$24.99
- Automated User Management and Data Processing Workflow$15.04
- AI Agent for Intelligent File Interaction in Supabase and Google Drive$19.99
- Automated Meditation Music Video Creation$19.99
- Instagram Reels Automation: Streamlined Content Creation & Publishing$19.99
- OpenAI Personal Shopper with RAG and WooCommerce$14.99
More from BestWorkflows
Need this deployed? We'll set it up for you.
Our automation experts deploy this workflow in your stack, connect your accounts, and verify it works — or build a custom solution from scratch.