Nested Data Processing Loops Using Sub-workflows - n8n Workflow

Master complex nested looping challenges in n8n by utilizing sub-workflows and the Execute Workflow n8n node. Download this reliable n8n template for modular data processing logic.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Automation specialists struggling to implement reliable nested loops in a single n8n workflow.
Developers requiring modular data processing structures.
Users looking for advanced n8n templates focusing on flow control.
Anyone interested in best practices for using the Execute Workflow n8n node.

Overview

While a powerful platform, n8n sometimes requires creative solutions for complex flow control patterns, such as nested loops (iterating over one list for every item in another list).

This robust n8n workflow template provides the definitive solution by separating the nested logic into two distinct components: a main workflow and a reusable sub-workflow. The main workflow uses the Split In Batches n8n node to iterate over the 'outer' list (Colors), and for each item, it calls a dedicated sub-workflow using the Execute Sub-workflow n8n node.

The sub-workflow receives the outer item as a parameter, executes its own inner loop (Integers), and combines the results. This approach ensures cleaner execution, prevents data mixing issues common in single-workflow looping structures, and showcases the power of the Execute Workflow n8n node for modular design. This n8n solution is essential for handling complex combinatorial data tasks.

How it Works

This automation is comprised of a main execution flow and a secondary sub-workflow logic, connected via the Execute Workflow n8n node.


  1. Main Workflow Trigger: The process starts with a manual n8n trigger, When clicking ‘Execute workflow’.

  2. Outer Data Initialization: The Colors Code n8n node generates the primary list (yellow, blue, green).

  3. Outer Loop: The Loop Over Colors Split In Batches n8n node begins iterating through the generated color list, processing one color per batch.

  4. Sub-workflow Execution: For each color item, the Execute Sub-workflow n8n node is called. It passes the current color value as an input parameter to the sub-workflow.

  5. Sub-workflow Trigger: The sub-workflow starts with the When Executed by Another Workflow n8n trigger, accepting the color parameter from the main n8n workflow.

  6. Inner Data Initialization: The Integers Code n8n node generates the secondary list (1, 2, 3).

  7. Inner Loop: The Loop Over Integers Split In Batches n8n node iterates through the integers.

  8. Data Combination: The Edit Fields Set n8n node performs the core processing. It combines the outer loop's color (received via the initial n8n trigger) with the current inner loop's number, producing a final result like 'yellow - 1'.

This structure ensures that for every item in the outer list, the entire inner n8n workflow sequence runs, reliably generating all required combinations.

Installation Guide

To deploy this powerful n8n workflow and its associated sub-workflow, follow these steps:


  1. Import: Copy the entire provided n8n workflow JSON and paste it into your n8n instance (New -> Import from JSON).

  2. Separate Sub-workflow: The provided template includes both the main and sub-workflow logic on one canvas. To function correctly, the sub-workflow part (starting with the When Executed by Another Workflow n8n node) must be moved to a separate, new n8n workflow canvas. Save this new sub-workflow.

  3. Link Workflows: Return to the main n8n workflow. Click on the Execute Sub-workflow n8n node.

  4. Configure Link: In the parameters, update the Sub-workflow field to select the exact name of the new workflow you created in Step 2. Ensure the input parameter color is correctly mapped as ={{ $json.color }}.

  5. Execution: Save and activate both the main n8n workflow and the sub-workflow. Execute the main workflow manually using the n8n trigger to observe the nested loop operation.

Node Details

When clicking ‘Execute workflow’ (Manual Trigger n8n trigger): Initiates the primary n8n workflow flow on demand.
Colors (Code n8n node): Generates the initial array data for the outer loop (the colors list). This demonstrates data preparation within an n8n node.
Loop Over Colors (Split In Batches n8n node): The primary flow control n8n node that handles batching the color list, ensuring the next step runs once per color item.
Execute Sub-workflow (Execute Workflow n8n node): The crucial connection node. For every item in the outer loop, it calls the separate sub-workflow. Key configuration: Passes color input to the downstream n8n workflow.
When Executed by Another Workflow (Execute Workflow Trigger n8n trigger): The entry point for the sub-workflow. It is configured to accept the color input passed by the main n8n workflow.
Integers (Code n8n node): Generates the array data for the inner loop (the numbers list) within the sub-workflow.
Loop Over Integers (Split In Batches n8n node): Controls the inner loop iteration, processing the number list one item at a time.
Edit Fields (Set n8n node): The final processing step. Uses n8n expressions to combine the incoming color data (from the n8n trigger) with the current number data (={{ $('When Executed by Another Workflow').item.json.color }} - {{ $('Loop Over Integers').item.json.number }}) into a combined result field.

Related n8n Workflows

Free

Nodes: 7 Nodes
Updated: December 26 2025
View all

Featured*