Who is this workflow for? This workflow showcases how to utilize the currentRunIndex in the Split In Batches node within n8n to monitor and control the execution flow based on the iteration count..

What does this workflow do?

  • Function Node:
  • Purpose: Generates mock data for the workflow.
  • Details: This node creates an array of items to be processed. Replace this node with your actual data source to split real data into batches.
   return [     { json: { item: 1 } },     { json: { item: 2 } },     { json: { item: 3 } },     { json: { item: 4 } },     { json: { item: 5 } },     { json: { item: 6 } }   ];
  1. Split In Batches Node:
    • Purpose: Divides the incoming data into batches.
    • Configuration: Set the batch size to 1 to process items individually. Adjust the batch size based on your specific requirements.
    • currentRunIndex: Tracks the current iteration index, starting from 0.
    1. IF Node:
      • Purpose: Evaluates the current run index to decide whether to continue or terminate the loop.
      • Condition: Checks if currentRunIndex equals 5 using the expression: plaintext {{$node["SplitInBatches"].context["currentRunIndex"]}}
      • Outcome: If true, the workflow breaks the loop; if false, it continues processing the next batch.
      1. Set Node:
        • Purpose: Executes actions based on the IF node’s outcome.
        • True Branch: Outputs the message Loop Ended, indicating the termination of the loop.
        • False Branch: Connect to the desired node to continue processing if the condition is not met.

        🤖 Why Use This Automation Workflow?

        • Control Workflow Execution: Easily manage and terminate workflows after a specific number of iterations.
        • Monitor Progress: Keep track of the current iteration index to make dynamic decisions within the workflow.
        • Optimize Processes: Prevent unnecessary processing by breaking loops based on defined conditions, enhancing efficiency.

        👨‍💻 Who is This Workflow For?

        This workflow is ideal for developers, workflow automators, and IT professionals who need to manage iterative processes within n8n, ensuring precise control over the number of executions and enhancing workflow reliability.

        🎯 Use Cases

        1. Data Processing Limits: Restrict the number of data items processed in a batch to prevent system overload.
        2. Task Scheduling: Execute a series of tasks a specific number of times before proceeding or terminating.
        3. Automated Reporting: Generate reports after processing a set number of records, ensuring timely and controlled output.

        TL;DR

        This n8n workflow effectively demonstrates the use of the Split In Batches node combined with currentRunIndex to monitor and control the execution flow. By implementing this template, you can manage iterative processes with precision, ensuring workflows run efficiently and terminate as needed based on predefined conditions.

Help us find the best n8n templates

About

A curated directory of the best n8n templates for workflow automations.