IF-node does not carry the result

Hello!

Consider the following workflow:

After the IF-node I had to include a Set-node, because no data would go to the FunctionItem-node (“Response OK”). On the Set-node I could leave it empty and turn Keep Only Set off, and data would magically appear.
Is there something wrong, or is this the normal behaviour of the IF-node?

Thank you!

Honestly sounds very strange and should not happen. Can you please post an example workflow to reproduce the problem. Thanks!

Sure.

First of all, I did not explain myself correctly.
The last node does contain the result, but it’s just not output to the webhook response. All I get is

{ "message": "Workflow did execute sucessfully but the last node did not return any data." }

instead of

{ "id": 1, name": "ZXS", ...} 

Here’s the non-working version (no Set in the middle):

{
"nodes": [
{
  "parameters": {},
  "name": "Start",
  "type": "n8n-nodes-base.start",
  "typeVersion": 1,
  "position": [
    250,
    300
  ]
},
{
  "parameters": {
    "httpMethod": "POST",
    "path": "user",
    "responseMode": "lastNode",
    "options": {}
  },
  "name": "Webhook",
  "type": "n8n-nodes-base.webhook",
  "typeVersion": 1,
  "position": [
    250,
    470
  ],
  "notesInFlow": false
},
{
  "parameters": {
    "conditions": {
      "boolean": [
        {
          "value1": "={{!!Object.keys($node[\"Get User\"].data).length}}",
          "value2": true
        }
      ]
    }
  },
  "name": "IF",
  "type": "n8n-nodes-base.if",
  "typeVersion": 1,
  "position": [
    650,
    400
  ],
  "retryOnFail": false
},
{
  "parameters": {
    "functionCode": "item.error = true;\nitem.message = \"No access\";\nreturn item;"
  },
  "name": "Response Error",
  "type": "n8n-nodes-base.functionItem",
  "typeVersion": 1,
  "position": [
    850,
    500
  ]
},
{
  "parameters": {
    "functionCode": "items[0].json.id = 1;\nitems[0].json.name = \"ZXS\";\nitems[0].json.secret = \"ABC123\"\n\nvar item = [];\nitem.push({json: {id: items[0].json.id, name: items[0].json.name, secret: items[0].json.secret}});\nreturn item;"
  },
  "name": "Get User",
  "type": "n8n-nodes-base.function",
  "typeVersion": 1,
  "position": [
    490,
    400
  ]
},
{
  "parameters": {
    "functionCode": "return items;"
  },
  "name": "Response OK",
  "type": "n8n-nodes-base.function",
  "typeVersion": 1,
  "position": [
    1060,
    330
  ]
},
{
  "parameters": {
    "options": {}
  },
  "name": "Set",
  "type": "n8n-nodes-base.set",
  "typeVersion": 1,
  "position": [
    840,
    280
  ]
}
],
"connections": {
"Webhook": {
  "main": [
    [
      {
        "node": "Get User",
        "type": "main",
        "index": 0
      }
    ]
  ]
},
"IF": {
  "main": [
    [
      {
        "node": "Response OK",
        "type": "main",
        "index": 0
      }
    ],
    [
      {
        "node": "Response Error",
        "type": "main",
        "index": 0
      }
    ]
  ]
},
"Get User": {
  "main": [
    [
      {
        "node": "IF",
        "type": "main",
        "index": 0
      }
    ]
  ]
}
}
}

And the working version (with Set):

{
"nodes": [
{
  "parameters": {},
  "name": "Start",
  "type": "n8n-nodes-base.start",
  "typeVersion": 1,
  "position": [
    250,
    300
  ]
},
{
  "parameters": {
    "httpMethod": "POST",
    "path": "user",
    "responseMode": "lastNode",
    "options": {}
  },
  "name": "Webhook",
  "type": "n8n-nodes-base.webhook",
  "typeVersion": 1,
  "position": [
    250,
    470
  ],
  "notesInFlow": false
},
{
  "parameters": {
    "conditions": {
      "boolean": [
        {
          "value1": "={{!!Object.keys($node[\"Get User\"].data).length}}",
          "value2": true
        }
      ]
    }
  },
  "name": "IF",
  "type": "n8n-nodes-base.if",
  "typeVersion": 1,
  "position": [
    650,
    400
  ],
  "retryOnFail": false
},
{
  "parameters": {
    "functionCode": "item.error = true;\nitem.message = \"No access\";\nreturn item;"
  },
  "name": "Response Error",
  "type": "n8n-nodes-base.functionItem",
  "typeVersion": 1,
  "position": [
    850,
    500
  ]
},
{
  "parameters": {
    "functionCode": "items[0].json.id = 1;\nitems[0].json.name = \"ZXS\";\nitems[0].json.secret = \"ABC123\"\n\nvar item = [];\nitem.push({json: {id: items[0].json.id, name: items[0].json.name, secret: items[0].json.secret}});\nreturn item;"
  },
  "name": "Get User",
  "type": "n8n-nodes-base.function",
  "typeVersion": 1,
  "position": [
    490,
    400
  ]
},
{
  "parameters": {
    "functionCode": "return items;"
  },
  "name": "Response OK",
  "type": "n8n-nodes-base.function",
  "typeVersion": 1,
  "position": [
    1060,
    330
  ]
},
{
  "parameters": {
    "options": {}
  },
  "name": "Set",
  "type": "n8n-nodes-base.set",
  "typeVersion": 1,
  "position": [
    840,
    280
  ]
}
],
"connections": {
"Webhook": {
  "main": [
    [
      {
        "node": "Get User",
        "type": "main",
        "index": 0
      }
    ]
  ]
},
"IF": {
  "main": [
    [
      {
        "node": "Set",
        "type": "main",
        "index": 0
      }
    ],
    [
      {
        "node": "Response Error",
        "type": "main",
        "index": 0
      }
    ]
  ]
},
"Get User": {
  "main": [
    [
      {
        "node": "IF",
        "type": "main",
        "index": 0
      }
    ]
  ]
},
"Set": {
  "main": [
    [
      {
        "node": "Response OK",
        "type": "main",
        "index": 0
      }
    ]
  ]
 }
}
}

I hope this is good example.

Thanks a lot for puting this together! That was very helpful. There was actually a bug. n8n thought the “Response Error” was the last node which got executed and for that reason it could not return any data as there was none. I fixed that bug now and will release it with the next version.

Will update here once it got released.

That’s so strange, because (at least on the UI Editor), the data flow would show correctly on the “Response OK” node.

Well, thank you for looking into it :slight_smile: Glad I could help.

Ah yes the UI displays it correctly. But underneath the hood did it set that also the error node got executed (as it was already in the stack). So even though it did not actually execute it, it got marked that way.

Fix got just released with [email protected]

2 Likes