IF node following a Failed node

I’d like to split my execution into two separate paths according to a status of a node, whether it failed on not. Note that I selected “Continue On Fail:” on that node so that execution doesn’t break.

The idea is to add an IF node following the one I’m interrogating and split the execution path from there.

My question - within the IF node, how can I query the status of the previous node (Failed, Passed)?

Hey @ayali!

Welcome to the community!

Currently, there is no way to get the status of the previous node. However, there is a work around for it. The following workflow might help.

In the following workflow, I’ve also set the Always Output Data to true for the Function node. If you change the code in the Function node to const items.json.myvariable... it will give an error. The IF node will check for this. If the Function gives an error the IF node will return true otherwise false. Depending on the node that you have prior to the IF node, you may have to modify the condition in the IF node.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        300
      ],
      "alwaysOutputData": true,
      "continueOnFail": true
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{!!Object.keys($json).length}}"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {},
      "name": "Workflow Failed",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        850,
        200
      ]
    },
    {
      "parameters": {},
      "name": "Workflow Success",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        850,
        400
      ]
    }
  ],
  "connections": {
    "Function": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Workflow Failed",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Workflow Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Thanks for your assistance.
I’ve taken an existing Function node, so I’m not sure I can easily change its code, as you suggested.

I’m actually looking now at the Error Trigger node, but with this case it seems that I’m losing all data captured by the nodes in the failed workflow.

The workflow that I share was an example. You will have to modify it as per your use-case. The Error Trigger node only gets the information about the workflow and the node that caused the error. It won’t get the data from the workflows.

Thank you. Indeed works well!