[IF Node] Returning false when true condition

Hello, in this image i’ve used output data (parsed as int with parseInt) and dates (like month and day also parsed with parseInt). In the image clearly it should return True but it goes on the False condition.

I would check the expressions cuz it’s working just fine for me. Make sure you are not comparing a string with a number.

I’m comparing for example

 {{parseInt($json["DAY"])}} = Return 10
 {{parseInt(new Date().getDate())}} = Returns 10

This conditional returns False but the statement below returns True

   {{parseInt($json["MONTH"])}} = Return 3
   {{parseInt(new Date().getMonth()+1)}} = Returns 3

Clearly the problem is comparing 10 with 10. Did you see any error in the expression?

Did never come across a case where the IF node did behave wrong. So can do not belibe that it does suddenly here as we did not change anything in the logic for a very long time.

Is it possible that you have multiple items and for some it returns true (and so they end up in “true”) and for the others false (and so they end up in “false”)? Or asking differently. When you select the output “true” does it then say “Results: 0”?

1 Like

This is the flow i’m using to test. In my original flow i have more RSS Nodes to read multiple GitHub repositories. Indeed all items returns false, even the ones that should match the condition.

Hey @Bo_Wyatt!

You’re getting an unexpected result because of a space in your expression. The Value 1 in your IF node has an extra space before the expression. = {{Number($json[\"DAY\"])}}. If you remove that space, your workflow should work as expected. Here’s the updated workflow:

Thank you! That worked, i never imagined that i could be that. Now I can control Releases on GitHub Projects.

1 Like

Thanks to @Ben for pointing it out!
I am looking forward to see what you build :slightly_smiling_face:

2 Likes

i have a very similar problem with my IF nodes.

I am comparing string values from mautic and pipedrive.
node looks like this:

I keep getting a wrong output based on the values I compare. I already tried it with different operators (equals, not equal), but problem remains.
I also checked if there is any spaces which could cause an error.

Note: To make the data comparable, i had to set some of the values beforehand via set node (example: empty field values soemtimes had no result. these i had to set to [Object: null].
Although all the output looks fine, but the node doesn’t behave in the same manner…

Any ideas what could be the issue?

@iundf_Marketing_Tech I ran into a similar issue. You are not alone :slight_smile:

This is what I found out (after working on such things for countless hours wondering if the IF node was working as it should.

  • I found it’s best to assume that a core node like the IF node is working. (always good to start with this assumption)
  • Try to simplify your data for such IF nodes - If you need to make something very complex you can do so by adding one variable after testing the one before
    So for example in your case you can break down this one BIG IF node into about 17 small IF nodes and it will do the same job but will be SO SO SO much simpler to find out where the issue is.
  • Make sure to first test the node on 1 record before running on a batch of records (this could be the code of the issue of the IF node not feeling like its running as intended)
    image

Hope that helps out with my train of thought of how I would try to figure out the root of this.

1 Like

Thank you @David_Go

We could solve the problem part time. But testing the following day, led again to the same problems.

Also this node should clearly be a true outcome, yet it is not:

{
  "nodes": [
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"Webhook\"].json[\"body\"][\"mautic.company_post_save\"][0][\"company\"][\"fields\"][\"core\"][\"pipedrive_id_organisation\"][\"value\"]}}",
              "value2": "={{$node[\"Pipedrive get company\"].json[\"id\"]}}"
            }
          ]
        }
      },
      "name": "IF1",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1200,
        980
      ]
    }
  ],
  "connections": {}
}```

Any ideas what happened here?

Since the data is coming from different parts of your flow it’s really hard to tell that the data is really the same :slight_smile:

There is probably something else going on in the flow that is tossing everything off wack…
I ran into this exact same issue : ) and yeah, the sample values you get in the IF node looks right… but it doesn’t always mean the full flow is set up correctly. (this has been my experience)

Can you provide me a simple screenshot of the flow this can help diagnose the issue.

forgot to tag you @David_Go

This is the example i am working on right now. In this flow i am comparing data for the two nodes before (marked in the picture)


I ran into the same problem. The data looks the same to me (already tried to compare stirngs and numbers with the same result.

The if nodes looks as following:

{
  "nodes": [
    {
      "parameters": {
        "conditions": {
          "string": [],
          "number": [
            {
              "value1": "={{$node[\"Search Organisation\"].json[\"id\"]}}",
              "operation": "equal",
              "value2": "={{$node[\"Mautic get company\"].json[\"org_pipedrive_id\"]}}"
            }
          ]
        },
        "combineOperation": "any"
      },
      "name": "choose right company",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        720,
        840
      ]
    }
  ],
  "connections": {}
}```

Any idea what might be the issue?

Best Janic

@iundf_Marketing_Tech

Can you test putting the company ID under a string rather than a number, not sure why but I ran into this in the past and that fixed it.

1 Like

Hey @David_Go

Thank you for your feedback. It happened again in a different environment:

Also i tried strings and numbers, with no luck.

This is the node:

The output should be true not false. Any idea what could cause this confusion or how to fix it?

@iundf_Marketing_Tech

Based on the info provided I agree that this looks a bit concerning.

That being said, anytime I had such an issue it was usually not because the node was not working as intended. it was usually 1) an error in the data sent or 2) an error in the node setup.

I would try to take a closer look at the record itself in Mautic and Pipedrive to see if there is anything that stands out from the rest that simply works.

Also, you might want to try adding a Set node before the If node to only take the 2 fields you are comparing to reduce other unforeseen variables.

Just thoughts on how I solved things in my n8n flows in the past.

2 Likes

Thanks @David_Go, i will try this and post results here.

We found the issue. In comparison steps, values and field types are compared. This means that even if the values are the same but the field types aren’t, the output is going to be false instead of true.

Thus, to resolve this, you just have to make sure, that the field types are the same.

Thanks @David_Go for your help.

Hi everyone! Facing the similar issue with my IF node. My scenario is

  1. Go to PostgreSQL and look for email, return count of such email id DB
  2. IF count >= 1 – no operation, if count = 0 – perform further action.
    I’m doing numeric comparison, please see the screenshot attached

    Could you please advise a proper way to execute such comparison?

Hi @alexpti4ka, the double quotes around the 1 from your screenshot suggest your count is string. Could you try your comparison using a string condition?