diff --git a/packages/nodes-base/nodes/SplitInBatches/test/SplitInBatches.workflow_v2_done_variable.json b/packages/nodes-base/nodes/SplitInBatches/test/SplitInBatches.workflow_v2_done_variable.json new file mode 100644 index 0000000000..d9d239adc0 --- /dev/null +++ b/packages/nodes-base/nodes/SplitInBatches/test/SplitInBatches.workflow_v2_done_variable.json @@ -0,0 +1,738 @@ +{ + "name": "My workflow 91", + "nodes": [ + { + "parameters": {}, + "id": "75920640-6f1e-41dc-b8c0-bc2f21c823a5", + "name": "When clicking \"Execute Workflow\"", + "type": "n8n-nodes-base.manualTrigger", + "typeVersion": 1, + "position": [740, 1100] + }, + { + "parameters": { + "conditions": { + "boolean": [ + { + "value1": "={{ $node[\"Split In Batches 3_2\"].context[\"noItemsLeft\"] }}", + "value2": true + } + ] + } + }, + "id": "ca59e1fe-83df-4cf8-9cbb-d3ea6a8a7247", + "name": "No Items Left", + "type": "n8n-nodes-base.if", + "typeVersion": 1, + "position": [2320, 1560] + }, + { + "parameters": { + "batchSize": 1, + "options": {} + }, + "id": "21991c05-c919-405b-a0d7-e1dafa5a5e74", + "name": "Split In Batches 1", + "type": "n8n-nodes-base.splitInBatches", + "typeVersion": 2, + "position": [1220, 840] + }, + { + "parameters": { + "batchSize": 1, + "options": { + "reset": "={{ $node[\"Split In Batches 1_2\"].context[\"done\"] }}" + } + }, + "id": "3b3ecf28-b865-4995-a34d-587047b9887a", + "name": "Split In Batches 1_2", + "type": "n8n-nodes-base.splitInBatches", + "typeVersion": 2, + "position": [1840, 900] + }, + { + "parameters": { + "content": "# V2 with done branch and \"done\" variable", + "height": 221.18781425126934 + }, + "id": "558ca8c2-1d75-44c1-81ee-8614e1bdc36a", + "name": "Sticky Note", + "type": "n8n-nodes-base.stickyNote", + "typeVersion": 1, + "position": [660, 816.8121857487308] + }, + { + "parameters": { + "content": "# V2 with IF", + "height": 113.61217587373169 + }, + "id": "08957c26-00d4-459b-9497-7b0636086575", + "name": "Sticky Note4", + "type": "n8n-nodes-base.stickyNote", + "typeVersion": 1, + "position": [660, 1320] + }, + { + "parameters": { + "conditions": { + "boolean": [ + { + "value1": "={{ $node[\"Split In Batches 2_2\"].context[\"noItemsLeft\"] }}", + "value2": true + } + ] + } + }, + "id": "a38109ba-672e-4bd0-ac66-e243d53d2252", + "name": "No Items Left2", + "type": "n8n-nodes-base.if", + "typeVersion": 1, + "position": [2320, 1320] + }, + { + "parameters": { + "content": "# V1 with IF", + "height": 113.61217587373169 + }, + "id": "d5f45e34-21f6-4dc0-bf54-2bbbea561aed", + "name": "Sticky Note8", + "type": "n8n-nodes-base.stickyNote", + "typeVersion": 1, + "position": [660, 1560] + }, + { + "parameters": { + "conditions": { + "boolean": [ + { + "value1": "={{ $node[\"Split In Batches 3\"].context[\"noItemsLeft\"] }}", + "value2": true + } + ] + } + }, + "id": "1787b55b-4e33-4034-8043-33d21e78cd30", + "name": "IF", + "type": "n8n-nodes-base.if", + "typeVersion": 1, + "position": [2540, 1540] + }, + { + "parameters": { + "conditions": { + "boolean": [ + { + "value1": "={{ $node[\"Split In Batches 2\"].context[\"noItemsLeft\"] }}", + "value2": true + } + ] + } + }, + "id": "e149b5d7-7a7f-4939-88e4-789e987cf280", + "name": "IF1", + "type": "n8n-nodes-base.if", + "typeVersion": 1, + "position": [2540, 1300] + }, + { + "parameters": { + "jsCode": "return [\n {\n key: '0'\n },\n {\n key: '1'\n }\n];" + }, + "id": "cf21ca09-ca2e-4334-a6ea-e7453d8598ca", + "name": "Mock Data 1", + "type": "n8n-nodes-base.code", + "typeVersion": 1, + "position": [1000, 840] + }, + { + "parameters": { + "jsCode": "return [\n {\n key: '10_' + $runIndex\n },\n {\n key: '11_' + $runIndex\n },\n {\n key: '12_' + $runIndex\n },\n {\n key: '13_' + $runIndex\n },\n {\n key: '14_' + $runIndex\n },\n];" + }, + "id": "2a62fdd8-5e6c-468b-88af-bddd0475ff4a", + "name": "Mock Data 1_2", + "type": "n8n-nodes-base.code", + "typeVersion": 1, + "position": [1580, 820] + }, + { + "parameters": { + "jsCode": "return [\n {\n key: '0'\n },\n {\n key: '1'\n }\n];" + }, + "id": "f4b7b020-7d07-4aff-a99b-f0d6bfe656ff", + "name": "Mock Data 2", + "type": "n8n-nodes-base.code", + "typeVersion": 1, + "position": [1000, 1280] + }, + { + "parameters": { + "jsCode": "return [\n {\n key: '10_' + $runIndex\n },\n {\n key: '11_' + $runIndex\n },\n {\n key: '12_' + $runIndex\n },\n {\n key: '13_' + $runIndex\n },\n {\n key: '14_' + $runIndex\n },\n];" + }, + "id": "9f9e4c1f-5dfc-45f6-ac48-ccd02d42e54c", + "name": "Mock Data 2_2", + "type": "n8n-nodes-base.code", + "typeVersion": 1, + "position": [1580, 1260] + }, + { + "parameters": { + "jsCode": "return [\n {\n key: '0'\n },\n {\n key: '1'\n }\n];" + }, + "id": "d20015b3-6e15-4094-bd18-c62be7fbcf9e", + "name": "Mock Data 3", + "type": "n8n-nodes-base.code", + "typeVersion": 1, + "position": [1000, 1560] + }, + { + "parameters": { + "jsCode": "return [\n {\n key: '10_' + $runIndex\n },\n {\n key: '11_' + $runIndex\n },\n {\n key: '12_' + $runIndex\n },\n {\n key: '13_' + $runIndex\n },\n {\n key: '14_' + $runIndex\n },\n];" + }, + "id": "9b8f1472-3913-44ae-9e8c-e8bf01d5ea3c", + "name": "Mock Data 3_2", + "type": "n8n-nodes-base.code", + "typeVersion": 1, + "position": [1580, 1560] + }, + { + "parameters": {}, + "id": "11b6d860-ce7b-4e5c-b5eb-5ec4387092c1", + "name": "Results 1", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [1400, 920] + }, + { + "parameters": { + "jsCode": "let results = [],\n i = 0;\n\ndo {\n try {\n results = results.concat($(\"Some Operation 2\").all(0, i));\n } catch (error) {\n return results;\n }\n i++;\n} while (true);\n" + }, + "id": "84277fcb-2749-49f3-83f3-7132848f3a0b", + "name": "Result 2", + "type": "n8n-nodes-base.code", + "position": [2860, 1280], + "typeVersion": 1 + }, + { + "parameters": { + "jsCode": "let results = [],\n i = 0;\n\ndo {\n try {\n results = results.concat($(\"Some Operation 3\").all(0, i));\n } catch (error) {\n return results;\n }\n i++;\n} while (true);\n" + }, + "id": "fd9de431-a537-44a6-a4e2-68825768bb1d", + "name": "Result 3", + "type": "n8n-nodes-base.code", + "position": [2860, 1520], + "typeVersion": 1 + }, + { + "parameters": {}, + "id": "9a62eed8-9c40-4763-92e9-9633b77a37cf", + "name": "Some Operation 1", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [2100, 880] + }, + { + "parameters": {}, + "id": "cb35f9e6-7379-484b-b770-5eecba535a83", + "name": "Some Operation 2", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [2100, 1320] + }, + { + "parameters": {}, + "id": "62a66c9d-2a66-4c77-b4a2-0db89574074d", + "name": "Some Operation 3", + "type": "n8n-nodes-base.noOp", + "typeVersion": 1, + "position": [2100, 1560] + }, + { + "parameters": { + "batchSize": 1, + "options": {} + }, + "id": "2ac3d20c-8891-4854-bca1-188f0e9542ac", + "name": "Split In Batches 3", + "type": "n8n-nodes-base.splitInBatches", + "typeVersion": 1, + "position": [1220, 1560] + }, + { + "parameters": { + "batchSize": 1, + "options": {} + }, + "id": "d37b3b09-1255-486d-99ed-cffcc9f87548", + "name": "Split In Batches 2", + "type": "n8n-nodes-base.splitInBatches", + "typeVersion": 2, + "position": [1220, 1280] + }, + { + "parameters": { + "batchSize": 1, + "options": { + "reset": "={{ $node[\"Split In Batches 3_2\"].context[\"noItemsLeft\"] }}" + } + }, + "id": "89a74a96-e3f7-4306-b68b-fa82254ccca3", + "name": "Split In Batches 3_2", + "type": "n8n-nodes-base.splitInBatches", + "typeVersion": 1, + "position": [1840, 1560] + }, + { + "parameters": { + "batchSize": 1, + "options": { + "reset": "={{ $node[\"Split In Batches 2_2\"].context[\"noItemsLeft\"] }}" + } + }, + "id": "2cc3f863-e388-494f-ba9d-e18ac28df5ee", + "name": "Split In Batches 2_2", + "type": "n8n-nodes-base.splitInBatches", + "typeVersion": 2, + "position": [1840, 1340] + } + ], + "pinData": { + "Results 1": [ + { + "json": { + "key": "10_0" + } + }, + { + "json": { + "key": "11_0" + } + }, + { + "json": { + "key": "12_0" + } + }, + { + "json": { + "key": "13_0" + } + }, + { + "json": { + "key": "14_0" + } + }, + { + "json": { + "key": "10_1" + } + }, + { + "json": { + "key": "11_1" + } + }, + { + "json": { + "key": "12_1" + } + }, + { + "json": { + "key": "13_1" + } + }, + { + "json": { + "key": "14_1" + } + } + ], + "Result 3": [ + { + "json": { + "key": "10_0" + } + }, + { + "json": { + "key": "11_0" + } + }, + { + "json": { + "key": "12_0" + } + }, + { + "json": { + "key": "13_0" + } + }, + { + "json": { + "key": "14_0" + } + }, + { + "json": { + "key": "10_1" + } + }, + { + "json": { + "key": "11_1" + } + }, + { + "json": { + "key": "12_1" + } + }, + { + "json": { + "key": "13_1" + } + }, + { + "json": { + "key": "14_1" + } + } + ], + "Result 2": [ + { + "json": { + "key": "10_0" + } + }, + { + "json": { + "key": "11_0" + } + }, + { + "json": { + "key": "12_0" + } + }, + { + "json": { + "key": "13_0" + } + }, + { + "json": { + "key": "14_0" + } + }, + { + "json": { + "key": "10_1" + } + }, + { + "json": { + "key": "11_1" + } + }, + { + "json": { + "key": "12_1" + } + }, + { + "json": { + "key": "13_1" + } + }, + { + "json": { + "key": "14_1" + } + } + ] + }, + "connections": { + "When clicking \"Execute Workflow\"": { + "main": [ + [ + { + "node": "Mock Data 1", + "type": "main", + "index": 0 + }, + { + "node": "Mock Data 2", + "type": "main", + "index": 0 + }, + { + "node": "Mock Data 3", + "type": "main", + "index": 0 + } + ] + ] + }, + "No Items Left": { + "main": [ + [ + { + "node": "IF", + "type": "main", + "index": 0 + } + ], + [ + { + "node": "Split In Batches 3_2", + "type": "main", + "index": 0 + } + ] + ] + }, + "Split In Batches 1": { + "main": [ + [ + { + "node": "Mock Data 1_2", + "type": "main", + "index": 0 + } + ], + [ + { + "node": "Results 1", + "type": "main", + "index": 0 + } + ] + ] + }, + "Split In Batches 1_2": { + "main": [ + [ + { + "node": "Some Operation 1", + "type": "main", + "index": 0 + } + ], + [ + { + "node": "Split In Batches 1", + "type": "main", + "index": 0 + } + ] + ] + }, + "No Items Left2": { + "main": [ + [ + { + "node": "IF1", + "type": "main", + "index": 0 + } + ], + [ + { + "node": "Split In Batches 2_2", + "type": "main", + "index": 0 + } + ] + ] + }, + "IF": { + "main": [ + [ + { + "node": "Result 3", + "type": "main", + "index": 0 + } + ], + [ + { + "node": "Split In Batches 3", + "type": "main", + "index": 0 + } + ] + ] + }, + "IF1": { + "main": [ + [ + { + "node": "Result 2", + "type": "main", + "index": 0 + } + ], + [ + { + "node": "Split In Batches 2", + "type": "main", + "index": 0 + } + ] + ] + }, + "Mock Data 1": { + "main": [ + [ + { + "node": "Split In Batches 1", + "type": "main", + "index": 0 + } + ] + ] + }, + "Mock Data 1_2": { + "main": [ + [ + { + "node": "Split In Batches 1_2", + "type": "main", + "index": 0 + } + ] + ] + }, + "Mock Data 2": { + "main": [ + [ + { + "node": "Split In Batches 2", + "type": "main", + "index": 0 + } + ] + ] + }, + "Mock Data 2_2": { + "main": [ + [ + { + "node": "Split In Batches 2_2", + "type": "main", + "index": 0 + } + ] + ] + }, + "Mock Data 3": { + "main": [ + [ + { + "node": "Split In Batches 3", + "type": "main", + "index": 0 + } + ] + ] + }, + "Mock Data 3_2": { + "main": [ + [ + { + "node": "Split In Batches 3_2", + "type": "main", + "index": 0 + } + ] + ] + }, + "Some Operation 1": { + "main": [ + [ + { + "node": "Split In Batches 1_2", + "type": "main", + "index": 0 + } + ] + ] + }, + "Some Operation 2": { + "main": [ + [ + { + "node": "No Items Left2", + "type": "main", + "index": 0 + } + ] + ] + }, + "Some Operation 3": { + "main": [ + [ + { + "node": "No Items Left", + "type": "main", + "index": 0 + } + ] + ] + }, + "Split In Batches 3": { + "main": [ + [ + { + "node": "Mock Data 3_2", + "type": "main", + "index": 0 + } + ] + ] + }, + "Split In Batches 2": { + "main": [ + [ + { + "node": "Mock Data 2_2", + "type": "main", + "index": 0 + } + ] + ] + }, + "Split In Batches 3_2": { + "main": [ + [ + { + "node": "Some Operation 3", + "type": "main", + "index": 0 + } + ] + ] + }, + "Split In Batches 2_2": { + "main": [ + [ + { + "node": "Some Operation 2", + "type": "main", + "index": 0 + } + ] + ] + } + }, + "active": false, + "settings": {}, + "versionId": "027162aa-0b6a-4cd5-9bf6-345b70c83f2d", + "id": "1124", + "meta": { + "instanceId": "021d3c82ba2d3bc090cbf4fc81c9312668bcc34297e022bb3438c5c88a43a5ff" + }, + "tags": [] +} diff --git a/packages/nodes-base/nodes/SplitInBatches/v2/SplitInBatchesV2.node.ts b/packages/nodes-base/nodes/SplitInBatches/v2/SplitInBatchesV2.node.ts index 31252fd483..27405a039c 100644 --- a/packages/nodes-base/nodes/SplitInBatches/v2/SplitInBatchesV2.node.ts +++ b/packages/nodes-base/nodes/SplitInBatches/v2/SplitInBatchesV2.node.ts @@ -153,9 +153,12 @@ export class SplitInBatchesV2 implements INodeType { nodeContext.noItemsLeft = nodeContext.items.length === 0; if (returnItems.length === 0) { + nodeContext.done = true; return [[], nodeContext.processedItems]; } + nodeContext.done = false; + return [returnItems, []]; } }