Hi guys,
I have a problem with the if node.
If I perform a data-merge over a function after a “split in batch” and then check the variable “isDev” from the “.env”-function defined before (before the split in batch) for “true” after the batch I get true AND false in one pass. For checkup: Function2 has a console.log($node[".env"].json["isDev"]);
Is this a bug or a feature?
For a better understanding I have built a pseudo-workflow.
The workflow was executed on version 0.95.1
In the real Zenario a http request with different configurations is executed within the “Split in Batch”. The result should and will be summarized afterwards.
{
"name": "test-if",
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
250,
300
]
},
{
"parameters": {
"functionCode": "items[0].json.isDev = true;\nreturn items;"
},
"name": ".env",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
450,
300
]
},
{
"parameters": {
"functionCode": "for(let i = 0; i < 10; i++){\n items.push({json: {myVariable: i}});\n}\n\nreturn items;"
},
"name": "Function",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
640,
300
]
},
{
"parameters": {
"batchSize": 1,
"options": {}
},
"name": "SplitInBatches",
"type": "n8n-nodes-base.splitInBatches",
"typeVersion": 1,
"position": [
840,
300
]
},
{
"parameters": {
"functionCode": "items[0].json.hello= \"world\";\nreturn items;"
},
"name": "Function1",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
1040,
300
]
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{$node[\"SplitInBatches\"].context[\"noItemsLeft\"]}}",
"value2": true
}
]
}
},
"name": "IF",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
1240,
300
]
},
{
"parameters": {},
"name": "NoOp",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
1240,
500
]
},
{
"parameters": {},
"name": "NoOp1",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
1820,
140
]
},
{
"parameters": {},
"name": "NoOp2",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
1830,
590
]
},
{
"parameters": {
"functionCode": "console.log($node[\".env\"].json[\"isDev\"]);\nconst allData = [];\n\nlet counter = 1;\ndo {\n try {\n const items = $items(\"Function1\", 0, counter).map(item => item.json);\n allData.push({json: items});\n } catch (error) {\n return allData; \n }\n counter++;\n} while(true);\n\n"
},
"name": "Function2",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
1450,
300
]
},
{
"parameters": {},
"name": "NoOp3",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
2250,
370
]
},
{
"parameters": {},
"name": "NoOp4",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
2250,
520
]
},
{
"parameters": {},
"name": "NoOp5",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
2250,
70
]
},
{
"parameters": {},
"name": "NoOp6",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
2250,
220
]
},
{
"parameters": {},
"name": "NoOp7",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
2250,
670
]
},
{
"parameters": {},
"name": "NoOp8",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
2250,
820
]
},
{
"parameters": {},
"name": "NoOp9",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
1820,
930
]
},
{
"parameters": {},
"name": "NoOp10",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
1820,
1110
]
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{$node[\".env\"].json[\"isDev\"]}}",
"value2": true
}
]
}
},
"name": "isTrue",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
1630,
300
]
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{$node[\".env\"].json[\"isDev\"]}}"
}
]
}
},
"name": "isFalse",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
1630,
1000
]
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{$node[\".env\"].json[\"isDev\"]}}",
"value2": true
}
]
}
},
"name": "isTrue1",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
2030,
140
]
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{$node[\".env\"].json[\"isDev\"]}}",
"value2": true
}
]
}
},
"name": "isTrue2",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
2030,
430
]
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{$node[\".env\"].json[\"isDev\"]}}"
}
]
}
},
"name": "isFalse1",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
2030,
730
]
},
{
"parameters": {},
"name": "NoOp11",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
2210,
1040
]
},
{
"parameters": {},
"name": "NoOp12",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
2210,
1180
]
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{$node[\".env\"].json[\"isDev\"]}}",
"value2": true
}
]
}
},
"name": "isTrue3",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
2020,
1110
]
},
{
"parameters": {},
"name": "NoOp13",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
2210,
1350
]
},
{
"parameters": {},
"name": "NoOp14",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
2210,
1520
]
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{$node[\".env\"].json[\"isDev\"]}}"
}
]
}
},
"name": "isFalse2",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
2010,
1460
]
},
{
"parameters": {},
"name": "NoOp15",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
2600,
940
]
},
{
"parameters": {},
"name": "NoOp16",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
2600,
1110
]
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{$node[\".env\"].json[\"isDev\"]}}"
}
]
}
},
"name": "isFalse3",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
2400,
1040
]
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{$node[\".env\"].json[\"isDev\"]}}",
"value2": true
}
]
}
},
"name": "isTrue4",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
2420,
1320
]
},
{
"parameters": {},
"name": "NoOp17",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
2600,
1250
]
},
{
"parameters": {},
"name": "NoOp18",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
2600,
1410
]
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{$node[\".env\"].json[\"isDev\"]}}",
"value2": true
}
]
}
},
"name": "isTrue5",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
650,
580
]
},
{
"parameters": {},
"name": "NoOp19",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
840,
490
]
},
{
"parameters": {},
"name": "NoOp20",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
840,
680
]
}
],
"connections": {
"Start": {
"main": [
[
{
"node": ".env",
"type": "main",
"index": 0
}
]
]
},
".env": {
"main": [
[
{
"node": "isTrue5",
"type": "main",
"index": 0
},
{
"node": "Function",
"type": "main",
"index": 0
}
]
]
},
"Function": {
"main": [
[
{
"node": "SplitInBatches",
"type": "main",
"index": 0
}
]
]
},
"SplitInBatches": {
"main": [
[
{
"node": "Function1",
"type": "main",
"index": 0
}
]
]
},
"Function1": {
"main": [
[
{
"node": "IF",
"type": "main",
"index": 0
}
]
]
},
"IF": {
"main": [
[
{
"node": "Function2",
"type": "main",
"index": 0
}
],
[
{
"node": "NoOp",
"type": "main",
"index": 0
}
]
]
},
"NoOp": {
"main": [
[
{
"node": "SplitInBatches",
"type": "main",
"index": 0
}
]
]
},
"Function2": {
"main": [
[
{
"node": "isFalse",
"type": "main",
"index": 0
},
{
"node": "isTrue",
"type": "main",
"index": 0
}
]
]
},
"NoOp2": {
"main": [
[
{
"node": "isFalse1",
"type": "main",
"index": 0
},
{
"node": "isTrue2",
"type": "main",
"index": 0
}
]
]
},
"NoOp1": {
"main": [
[
{
"node": "isTrue1",
"type": "main",
"index": 0
}
]
]
},
"isTrue": {
"main": [
[
{
"node": "NoOp1",
"type": "main",
"index": 0
}
],
[
{
"node": "NoOp2",
"type": "main",
"index": 0
}
]
]
},
"isFalse": {
"main": [
[
{
"node": "NoOp9",
"type": "main",
"index": 0
}
],
[
{
"node": "NoOp10",
"type": "main",
"index": 0
}
]
]
},
"isTrue1": {
"main": [
[
{
"node": "NoOp5",
"type": "main",
"index": 0
}
],
[
{
"node": "NoOp6",
"type": "main",
"index": 0
}
]
]
},
"isTrue2": {
"main": [
[
{
"node": "NoOp3",
"type": "main",
"index": 0
}
],
[
{
"node": "NoOp4",
"type": "main",
"index": 0
}
]
]
},
"isFalse1": {
"main": [
[
{
"node": "NoOp7",
"type": "main",
"index": 0
}
],
[
{
"node": "NoOp8",
"type": "main",
"index": 0
}
]
]
},
"NoOp10": {
"main": [
[
{
"node": "isFalse2",
"type": "main",
"index": 0
},
{
"node": "isTrue3",
"type": "main",
"index": 0
}
]
]
},
"isTrue3": {
"main": [
[
{
"node": "NoOp11",
"type": "main",
"index": 0
}
],
[
{
"node": "NoOp12",
"type": "main",
"index": 0
}
]
]
},
"isFalse2": {
"main": [
[
{
"node": "NoOp13",
"type": "main",
"index": 0
}
],
[
{
"node": "NoOp14",
"type": "main",
"index": 0
}
]
]
},
"NoOp11": {
"main": [
[
{
"node": "isFalse3",
"type": "main",
"index": 0
}
]
]
},
"isFalse3": {
"main": [
[
{
"node": "NoOp15",
"type": "main",
"index": 0
}
],
[
{
"node": "NoOp16",
"type": "main",
"index": 0
}
]
]
},
"NoOp12": {
"main": [
[
{
"node": "isTrue4",
"type": "main",
"index": 0
}
]
]
},
"isTrue4": {
"main": [
[
{
"node": "NoOp17",
"type": "main",
"index": 0
}
],
[
{
"node": "NoOp18",
"type": "main",
"index": 0
}
]
]
},
"isTrue5": {
"main": [
[
{
"node": "NoOp19",
"type": "main",
"index": 0
}
],
[
{
"node": "NoOp20",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {},
"id": "8"
}