Verwendung von Sub-Workflows mit verschachtelten Schleifen
Fortgeschritten
Dies ist ein Engineering-Bereich Automatisierungsworkflow mit 9 Nodes. Hauptsächlich werden Set, Code, ManualTrigger, SplitInBatches, ExecuteWorkflow und andere Nodes verwendet. Erstellen Sie verschachtelte Datenverarbeitungsschleifen mit n8n-Subworkflows
Voraussetzungen
- •Keine besonderen Voraussetzungen, sofort nach Import nutzbar
Verwendete Nodes (9)
Kategorie
Workflow-Vorschau
Visualisierung der Node-Verbindungen, mit Zoom und Pan
Workflow exportieren
Kopieren Sie die folgende JSON-Konfiguration und importieren Sie sie in n8n
{
"id": "WX9Oa7y6UMwGUYBM",
"meta": {
"instanceId": "8981479cb588889c05b145eaed421551d37a4fff11ab279d3f4744a6577c6002"
},
"name": "Nested Loops with Sub-workflows",
"tags": [],
"nodes": [
{
"id": "f7e5c300-fad6-4fc7-a7ff-79f7fac144f0",
"name": "When clicking ‘Execute workflow’",
"type": "n8n-nodes-base.manualTrigger",
"position": [
0,
80
],
"parameters": {},
"typeVersion": 1
},
{
"id": "19f41efd-26ff-4950-9449-d52b8a98f040",
"name": "Colors",
"type": "n8n-nodes-base.code",
"position": [
224,
80
],
"parameters": {
"jsCode": "return [\n {\n \"color\": \"yellow\"\n },\n {\n \"color\": \"blue\"\n },\n {\n \"color\": \"green\"\n }\n];"
},
"typeVersion": 2
},
{
"id": "88109d36-2486-4b98-9377-893330490fb7",
"name": "Loop Over Colors",
"type": "n8n-nodes-base.splitInBatches",
"position": [
448,
80
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "c2b45eaa-eae7-45f6-b15f-6e863dedc71c",
"name": "When Executed by Another Workflow",
"type": "n8n-nodes-base.executeWorkflowTrigger",
"position": [
0,
304
],
"parameters": {
"workflowInputs": {
"values": [
{
"name": "color"
}
]
}
},
"typeVersion": 1.1
},
{
"id": "96372e82-0484-441b-a6d5-12ce5a1ea921",
"name": "Integers",
"type": "n8n-nodes-base.code",
"position": [
224,
304
],
"parameters": {
"jsCode": "return [\n {\n \"number\": 1\n },\n {\n \"number\": 2\n },\n {\n \"number\": 3\n }\n];"
},
"typeVersion": 2
},
{
"id": "f7a531e8-8fe1-4cf0-9a6a-3cd9ef57fdb8",
"name": "Loop Over Integers",
"type": "n8n-nodes-base.splitInBatches",
"position": [
448,
304
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "37b24ff0-165f-4a18-ae8a-c6054295fa87",
"name": "Edit Fields",
"type": "n8n-nodes-base.set",
"position": [
672,
304
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "3640152d-340b-4c27-b6f9-5735dcc93844",
"name": "result",
"type": "string",
"value": "={{ $('When Executed by Another Workflow').item.json.color }} - {{ $('Loop Over Integers').item.json.number }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "679311c7-3401-4f5c-b08b-a6bbf7fee61b",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-672,
80
],
"parameters": {
"width": 592,
"height": 512,
"content": "## Nested Loops with Sub-workflows\n### Template Description\nThis template provides a practical solution for a common n8n challenge: creating nested loops. While a powerful feature, n8n's standard **Loop** nodes don't work as expected in a nested structure. This template demonstrates the reliable workaround using a **main workflow** that calls a separate **sub-workflow** for each iteration.\n### Purpose\nThe template is designed to help you handle scenarios where you need to iterate through one list of data for every item in another list. This is a crucial pattern for combining or processing related data, ensuring your workflows are both clean and modular.\n### Instructions for Setup\n1. This template contains both the main workflow and the sub-workflow on a single canvas.\n2. **Copy the sub-workflow part** of this template (starting with the **Execute Sub-workflow Trigger** node) and paste it into a new, empty canvas.\n3. In the **Execute Sub-workflow** node in the **main workflow** on this canvas, update the `Sub-workflow` field to link to the new workflow you just created.\n4. Run the main workflow to see the solution in action.\n\n\nFor a detailed walkthrough of this solution, check out the [full blog post](https://n8nplaybook.com/post/2025/07/how-to-handle-nested-loops-in-n8n-with-sub-workflows/)"
},
"typeVersion": 1
},
{
"id": "51a07d4a-a6f5-4061-99ad-3379411c643b",
"name": "Execute Sub-workflow",
"type": "n8n-nodes-base.executeWorkflow",
"position": [
672,
80
],
"parameters": {
"options": {},
"workflowId": {
"__rl": true,
"mode": "list",
"value": "WX9Oa7y6UMwGUYBM",
"cachedResultName": "Nested Loops with Sub-workflows"
},
"workflowInputs": {
"value": {
"color": "={{ $json.color }}"
},
"schema": [
{
"id": "color",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "color",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [
"color"
],
"attemptToConvertTypes": false,
"convertFieldsToString": true
}
},
"typeVersion": 1.2
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "63176d07-d2a5-49fb-90bb-4c6cd8910fd0",
"connections": {
"19f41efd-26ff-4950-9449-d52b8a98f040": {
"main": [
[
{
"node": "88109d36-2486-4b98-9377-893330490fb7",
"type": "main",
"index": 0
}
]
]
},
"96372e82-0484-441b-a6d5-12ce5a1ea921": {
"main": [
[
{
"node": "f7a531e8-8fe1-4cf0-9a6a-3cd9ef57fdb8",
"type": "main",
"index": 0
}
]
]
},
"37b24ff0-165f-4a18-ae8a-c6054295fa87": {
"main": [
[
{
"node": "f7a531e8-8fe1-4cf0-9a6a-3cd9ef57fdb8",
"type": "main",
"index": 0
}
]
]
},
"88109d36-2486-4b98-9377-893330490fb7": {
"main": [
[],
[
{
"node": "51a07d4a-a6f5-4061-99ad-3379411c643b",
"type": "main",
"index": 0
}
]
]
},
"f7a531e8-8fe1-4cf0-9a6a-3cd9ef57fdb8": {
"main": [
[],
[
{
"node": "37b24ff0-165f-4a18-ae8a-c6054295fa87",
"type": "main",
"index": 0
}
]
]
},
"51a07d4a-a6f5-4061-99ad-3379411c643b": {
"main": [
[
{
"node": "88109d36-2486-4b98-9377-893330490fb7",
"type": "main",
"index": 0
}
]
]
},
"c2b45eaa-eae7-45f6-b15f-6e863dedc71c": {
"main": [
[
{
"node": "96372e82-0484-441b-a6d5-12ce5a1ea921",
"type": "main",
"index": 0
}
]
]
},
"f7e5c300-fad6-4fc7-a7ff-79f7fac144f0": {
"main": [
[
{
"node": "19f41efd-26ff-4950-9449-d52b8a98f040",
"type": "main",
"index": 0
}
]
]
}
}
}Häufig gestellte Fragen
Wie verwende ich diesen Workflow?
Kopieren Sie den obigen JSON-Code, erstellen Sie einen neuen Workflow in Ihrer n8n-Instanz und wählen Sie "Aus JSON importieren". Fügen Sie die Konfiguration ein und passen Sie die Anmeldedaten nach Bedarf an.
Für welche Szenarien ist dieser Workflow geeignet?
Fortgeschritten - Engineering
Ist es kostenpflichtig?
Dieser Workflow ist völlig kostenlos. Beachten Sie jedoch, dass Drittanbieterdienste (wie OpenAI API), die im Workflow verwendet werden, möglicherweise kostenpflichtig sind.
Verwandte Workflows
API-Architektur-Explorer
API-Architektur-Extraktor
If
Set
Code
+
If
Set
Code
88 NodesPolina Medvedieva
Engineering
Dokumenten-Frage-Antwort-System basierend auf Voyage-Context-3 Embeddings und MongoDB Atlas
Dokumenten-Frage-Antwort-System mit Voyage-Context-3-Embeddings und MongoDB Atlas
Set
Code
Wait
+
Set
Code
Wait
53 NodesJimleuk
Engineering
Web-Scraping mit n8N unter Umgehung von Cloudflare Turnstile
Web-Scraping mit 2captcha zum Umgehen von Cloudflare Turnstile
Set
Code
Wait
+
Set
Code
Wait
18 NodesLudwig
Engineering
Türme von Hanoi
Implementierung eines rekursiven Algorithmus mit Subworkflows: Hanoi-Turm-Demonstration
If
Set
Code
+
If
Set
Code
21 NodesAdrian
Engineering
Geschwindigkeitskritische Workflows durch parallele Verarbeitung optimieren (Fan-out/Fan-in)
🎓 Optimierung von zeitkritischen Workflows durch parallele Verarbeitung (Fan-out/Fan-in)
If
Set
Code
+
If
Set
Code
34 NodesLucas Peyrin
Engineering
Verwaltungssystem für Langlauf-Workflow-Status mit Warte-Knoten
System zur Verwaltung des Status von lang andauernden Workflows mit Warteknoten
If
Set
Code
+
If
Set
Code
42 NodesLucas Peyrin
Engineering
Workflow-Informationen
Schwierigkeitsgrad
Fortgeschritten
Anzahl der Nodes9
Kategorie1
Node-Typen7
Autor
Viktor Klepikovskyi
@vklepikovskyiExterne Links
Auf n8n.io ansehen →
Diesen Workflow teilen