IF node not matching input and evaluating as true

Hi folks,

I’ve just started using n8n today for a first workflow.

I have run into some problems with the UI, particularly around accessing and using the values that are passed along the flow.

I have an “execute command” node which runs a command line node script. I want to use the exit code from that script to pass on to an IF node.

The command executes, and I get a returnCode of 0.

But in the subsequent IF node, I can’t for the life of me work out how to get the if statement to evaluate that zero (is it a string? Is it a number?) and return true.

I’ve tried equality by number, string and by boolean. None of these evaluate as “true” for the input being zero.

I realise this looks very “I’m a beginner” - I must be doing something very basic that’s wrong here. Can anyone help?

Cheers folks!

Welcome to the community @stef!

It is a number. If you are unsure about the type you can add typeof in the expression. So you could write: {{typeof $node["Execute Command"].json["exitCode"]}}

Apart from that should it work exactly like you described. Here an example:

{
  "nodes": [
    {
      "parameters": {
        "command": "echo \"test\""
      },
      "name": "Execute Command",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        511,
        343
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{$node[\"Execute Command\"].json[\"exitCode\"]}}",
              "operation": "equal"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        661,
        343
      ]
    }
  ],
  "connections": {
    "Execute Command": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Thanks Jan. Appreciate that! I’ve realised I can use external npm modules, so I’ve now replaced that calling out to a CLI call with a JS function instead, which now works.

I’m still struggling with these IF statement builders though! I have a Postgres database that outputs an “gdrive_file_is_public” boolean, and I still can’t work out how to make an IF node return anything other than false based on that column! Like I said - I must be doing something fundamentally wrong here with the UI. Feels like I’m misunderstanding something very basic about it!

When I’m building the IF statement, I click on the part of the JSON structure I want to use, it says [Not found] in the UI in orange, despite the left hand object browser panel showing the key and the value are present. Perhaps this is the problem?

I’ve combined both views into this image so you can see the problem. I can’t upload more than one image as a new user here.

Just following that up with an observation. If rather than using the input data for that node, I click on the list of Nodes and select the node at the beginning of the flow that fetches the data from postgres, this display goes green and I then DO get a result from this IF node! :tada:

Why can’t you access the data that is being piped to the IF node though? That seems quite counter-intuitive.

Not exactly sure what is going wrong in your workflow but the Expression-Editor always displays the data from the first output. So if you reference data from an IF-Node that could be a problem. In this case I would recommend you to add a NoOp-Node to the “false” output and reference the data from there.

The Expression-Editor is currently not a perfect tool. It is just there to make the life of people easier when developing workflow. But no matter what it displays, when the workflow gets executed n8n will execute correctly.