[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”?

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.

   {
      "nodes": [
        {
          "parameters": {
            "batchSize": 1,
            "options": {
              "reset": false
            }
          },
          "name": "Extract Last Item4",
          "type": "n8n-nodes-base.splitInBatches",
          "position": [
            680,
            990
          ],
          "typeVersion": 1
        },
        {
          "parameters": {
            "conditions": {
              "number": [
                {
                  "value1": "= {{Number($json[\"DAY\"])}}",
                  "operation": "equal",
                  "value2": "={{Number(new Date().getDate())}}"
                }
              ]
            }
          },
          "name": "IF1",
          "type": "n8n-nodes-base.if",
          "typeVersion": 1,
          "position": [
            1230,
            940
          ],
          "executeOnce": true
        },
        {
          "parameters": {
            "value": "={{$json[\"pubDate\"]}}",
            "dataPropertyName": "DAY",
            "custom": true,
            "toFormat": "DD",
            "options": {}
          },
          "name": "Extract Day1",
          "type": "n8n-nodes-base.dateTime",
          "typeVersion": 1,
          "position": [
            880,
            900
          ]
        },
        {
          "parameters": {
            "value": "={{$json[\"pubDate\"]}}",
            "dataPropertyName": "MONTH",
            "custom": true,
            "toFormat": "MM",
            "options": {}
          },
          "name": "Extract Month1",
          "type": "n8n-nodes-base.dateTime",
          "typeVersion": 1,
          "position": [
            890,
            1050
          ]
        },
        {
          "parameters": {
            "mode": "mergeByIndex",
            "join": "inner"
          },
          "name": "Merge1",
          "type": "n8n-nodes-base.merge",
          "typeVersion": 1,
          "position": [
            1070,
            950
          ],
          "executeOnce": true
        },
        {
          "parameters": {},
          "name": "RSS Read",
          "type": "n8n-nodes-base.rssFeedRead",
          "position": [
            470,
            990
          ],
          "notesInFlow": true,
          "typeVersion": 1,
          "alwaysOutputData": true,
          "color": "#4A0C0C"
        }
      ],
      "connections": {
        "Extract Last Item4": {
          "main": [
            [
              {
                "node": "Extract Day1",
                "type": "main",
                "index": 0
              },
              {
                "node": "Extract Month1",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Extract Day1": {
          "main": [
            [
              {
                "node": "Merge1",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Extract Month1": {
          "main": [
            [
              {
                "node": "Merge1",
                "type": "main",
                "index": 1
              }
            ]
          ]
        },
        "Merge1": {
          "main": [
            [
              {
                "node": "IF1",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "RSS Read": {
          "main": [
            [
              {
                "node": "Extract Last Item4",
                "type": "main",
                "index": 0
              }
            ]
          ]
        }
      }
    }

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:

{
      "nodes": [
        {
          "parameters": {
            "batchSize": 1,
            "options": {
              "reset": false
            }
          },
          "name": "Extract Last Item4",
          "type": "n8n-nodes-base.splitInBatches",
          "position": [
            680,
            990
          ],
          "typeVersion": 1
        },
        {
          "parameters": {
            "conditions": {
              "number": [
                {
                  "value1": "={{Number($json[\"DAY\"])}}",
                  "operation": "equal",
                  "value2": "={{Number(new Date().getDate())}}"
                }
              ]
            }
          },
          "name": "IF1",
          "type": "n8n-nodes-base.if",
          "typeVersion": 1,
          "position": [
            1230,
            940
          ],
          "executeOnce": true
        },
        {
          "parameters": {
            "value": "={{$json[\"pubDate\"]}}",
            "dataPropertyName": "DAY",
            "custom": true,
            "toFormat": "DD",
            "options": {}
          },
          "name": "Extract Day1",
          "type": "n8n-nodes-base.dateTime",
          "typeVersion": 1,
          "position": [
            880,
            900
          ]
        },
        {
          "parameters": {
            "value": "={{$json[\"pubDate\"]}}",
            "dataPropertyName": "MONTH",
            "custom": true,
            "toFormat": "MM",
            "options": {}
          },
          "name": "Extract Month1",
          "type": "n8n-nodes-base.dateTime",
          "typeVersion": 1,
          "position": [
            890,
            1050
          ]
        },
        {
          "parameters": {
            "mode": "mergeByIndex",
            "join": "inner"
          },
          "name": "Merge1",
          "type": "n8n-nodes-base.merge",
          "typeVersion": 1,
          "position": [
            1070,
            950
          ],
          "executeOnce": true
        },
        {
          "parameters": {},
          "name": "RSS Read",
          "type": "n8n-nodes-base.rssFeedRead",
          "position": [
            470,
            990
          ],
          "notesInFlow": true,
          "typeVersion": 1,
          "alwaysOutputData": true,
          "color": "#4A0C0C"
        }
      ],
      "connections": {
        "Extract Last Item4": {
          "main": [
            [
              {
                "node": "Extract Day1",
                "type": "main",
                "index": 0
              },
              {
                "node": "Extract Month1",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Extract Day1": {
          "main": [
            [
              {
                "node": "Merge1",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Extract Month1": {
          "main": [
            [
              {
                "node": "Merge1",
                "type": "main",
                "index": 1
              }
            ]
          ]
        },
        "Merge1": {
          "main": [
            [
              {
                "node": "IF1",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "RSS Read": {
          "main": [
            [
              {
                "node": "Extract Last Item4",
                "type": "main",
                "index": 0
              }
            ]
          ]
        }
      }
    }

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