サブワークフローのネストされたループ
中級
これはEngineering分野の自動化ワークフローで、9個のノードを含みます。主にSet, Code, ManualTrigger, SplitInBatches, ExecuteWorkflowなどのノードを使用。 n8nのサブワークフローを使ってネストされたデータ処理ループを作成
前提条件
- •特別な前提条件なし、インポートしてすぐに使用可能
カテゴリー
ワークフロープレビュー
ノード接続関係を可視化、ズームとパンをサポート
ワークフローをエクスポート
以下のJSON設定をn8nにインポートして、このワークフローを使用できます
{
"id": "WX9Oa7y6UMwGUYBM",
"meta": {
"instanceId": "8981479cb588889c05b145eaed421551d37a4fff11ab279d3f4744a6577c6002"
},
"name": "Nested Loops with Sub-workflows",
"tags": [],
"nodes": [
{
"id": "f7e5c300-fad6-4fc7-a7ff-79f7fac144f0",
"name": "「ワークフローを実行」クリック時",
"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": "別ワークフローから実行時",
"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
}
]
]
}
}
}よくある質問
このワークフローの使い方は?
上記のJSON設定コードをコピーし、n8nインスタンスで新しいワークフローを作成して「JSONからインポート」を選択、設定を貼り付けて認証情報を必要に応じて変更してください。
このワークフローはどんな場面に適していますか?
中級 - エンジニアリング
有料ですか?
このワークフローは完全無料です。ただし、ワークフローで使用するサードパーティサービス(OpenAI APIなど)は別途料金が発生する場合があります。
関連ワークフロー
APIアーキテクチャ抽出ツール
APIアーキテクチャ抽出器
If
Set
Code
+
If
Set
Code
88 ノードPolina Medvedieva
エンジニアリング
Voyage-Context-3 エンベディングと MongoDB Atlas に基づくドキュメントQ&Aシステム
Voyage-Context-3埋め込みモデルおよびMongoDB Atlasを基盤としたドキュメントQ&Aシステム
Set
Code
Wait
+
Set
Code
Wait
53 ノードJimleuk
エンジニアリング
Cloudflare Turnstileを回避してn8nでウェブスクレイピング
Cloudflare Turnstileのブロックを2captchaを使って突破してウェブスクレイピング
Set
Code
Wait
+
Set
Code
Wait
18 ノードLudwig
エンジニアリング
ハノイの塔
サブワークフローによる再帰アルゴリズムの実装:ハノイの塔デモ
If
Set
Code
+
If
Set
Code
21 ノードAdrian
エンジニアリング
並列処理で速度を最適化した重要なワークフロー(ファンアウト-ファンイン)
並列処理(ファンアウト/ファンイン)を活用した速度クリティカルなワークフローを最適化
If
Set
Code
+
If
Set
Code
34 ノードLucas Peyrin
エンジニアリング
待機ノード付きの長時間実行ワークフロー状態管理システム
待機ノード付きの長時間実行ワークフロー状態管理システム
If
Set
Code
+
If
Set
Code
42 ノードLucas Peyrin
エンジニアリング