IF Result = false then wrong value

Hi All!

I am making progress with N8N and have build multiple workflows. However there is always more to build ;).

I have extended my workflow which is triggered by a webhook and request an API and gets the data out of JSON. I have made a condition with IF to see if the order is planned. If planned then it goed to true other to false. The IF node works and I have one result in the False route.

The problem is in MySQL node after the false. The ID that is passed true is of a different order.
You can see in the result box that it is different than of the False result in the IF node.

2020_09_24_12_07_59_n8n_️_Vplan_Collections_to_Productie

The ID is the first ID of the True path.
Can anybody explain what is wrong here?

Code:

[quote=“heestp, post:1, topic:2435, full:true”]
Hi All!

I am making progress with N8N and have build multiple workflows. However there is always more to build ;).

I have extended my workflow which is triggered by a webhook and request an API and gets the data out of JSON. I have made a condition with IF to see if the order is planned. If planned then it goed to true other to false. The IF node works and I have one result in the False route.

The problem is in MySQL node after the false. The ID that is passed true is of a different order.
You can see in the result box that it is different than of the False result in the IF node.

2020_09_24_12_07_59_n8n_️_Vplan_Collections_to_Productie

The ID is the first ID of the True path.

Can anybody explain what is wrong here?

Code:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        260,
        170
      ],
      "disabled": true
    },
    {
      "parameters": {
        "url": "https://api.vplan.nl/v1/collection?include=cards",
        "options": {},
        "headerParametersUi": {
          "parameter": [
            {
              "name": "X-Api-Env",
              "value": "6931b610a91e329921ab35ad66d53aa68af5d458"
            },
            {
              "name": "X-Api-Key",
              "value": "LbZyHsFZ7ynHlgLsIDLOvLoBl5qIX9cg5IOuiWe79fKFRrrNdpie04siNeStXlIc"
            }
          ]
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        550,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return items[0].json.data.map(item => {\n  return {\n    json: item,\n  }\n});"
      },
      "name": "Data to JSON",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        810,
        300
      ]
    },
    {
      "parameters": {
        "value": "={{$node[\"Data to JSON\"].json[\"cards\"][0][\"start\"]}}",
        "custom": true,
        "toFormat": "MMDD",
        "options": {}
      },
      "name": "Date & Time",
      "type": "n8n-nodes-base.dateTime",
      "typeVersion": 1,
      "position": [
        1150,
        120
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"Data to JSON\"].json[\"status\"]}}",
              "value2": "planned"
            }
          ]
        }
      },
      "name": "IF Planned",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        980,
        300
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=UPDATE werkorders SET volgorde = 9999 WHERE vplan_id = \"{{$node[\"IF Planned\"].json[\"id\"]}}\""
      },
      "name": "MySQL -> 9999",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 1,
      "position": [
        1460,
        320
      ],
      "credentials": {
        "mySql": "Katjang"
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=UPDATE werkorders SET volgorde = {{$node[\"Date & Time\"].json[\"data\"]}}{{$node[\"Date & Time\"].json[\"cards\"][0][\"position\"]}} WHERE vplan_id = \"{{$node[\"Date & Time\"].json[\"id\"]}}\""
      },
      "name": "MySQL Volgorde",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 1,
      "position": [
        1460,
        120
      ],
      "credentials": {
        "mySql": "Katjang"
      }
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Data to JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Data to JSON": {
      "main": [
        [
          {
            "node": "IF Planned",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Date & Time": {
      "main": [
        [
          {
            "node": "MySQL Volgorde",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF Planned": {
      "main": [
        [
          {
            "node": "Date & Time",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "MySQL -> 9999",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Hi @heestp! For the MySQL node connected to the false output of the IF node, can you change the expression in the Query field to UPDATE werkorders SET volgorde = 9999 WHERE vplan_id = "{{$json["id"]}}" and check if executing that works?

Thanks for the quick response!
However it still doesn’t work…

Hi @heestp, the Editor UI shows the first result from the IF node. However, the actual data pushed into MySQL should be correct with the expression I mentioned above. I just tried it locally and it works correctly.

You can check that by adding a Function node and connecting it to the false output which will show you the expected result in the terminal. Here’s the code for the Function node if you’d like to try that out:

console.log($json["id"]);
return items;

Hope that helps!

Hi Tanay,

It was passed wrongly to MySQL that s how I found out. I know have a SET (empty) node between the IF and MySQL and now it works.

1 Like

Great to hear that it worked out! Have fun! :slight_smile:

The $node always gets the data of the node from the first output, in this case true. If you want to simply use the data that gets sent into the node you can use $json instead.

So change $node['IF Planned'].json["id"] to $json["id"]

1 Like

Hi Jan,

As you can read above. I tried that and that did not help.
I now solved it with a work-around by placing a SET in between. The SET does nothing.

Yes, I saw that but ignoring that seemed nicer than me having to say “you are wrong check again”.

Example workflow:

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      number: 1\n    }\n  },\n  {\n    json: {\n      number: 2\n    }\n  }\n];"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        500,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{$json[\"number\"]}}",
              "operation": "equal",
              "value2": 1
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        700,
        300
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "number": [
            {
              "name": "myNumberJson",
              "value": "={{$json[\"number\"]}}"
            },
            {
              "name": "myNumberNode",
              "value": "={{$node[\"IF\"].json[\"number\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set True",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        900,
        210
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "number": [
            {
              "name": "myNumberJson",
              "value": "={{$json[\"number\"]}}"
            },
            {
              "name": "myNumberNode",
              "value": "={{$node[\"IF\"].json[\"number\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set False",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        900,
        400
      ]
    }
  ],
  "connections": {
    "Function": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Set True",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set False",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Screenshot from 2020-09-24 18-33-29

Data of “Set True” after it got executed:

Data of “Set False” after it got executed:

Hi Jan and Tanay,

Thanks for the help! I found out that Janay was right. In the designer it shows the wrong value (see picture) but when you execute the workflow the correct (IF -> False) data will be passed.

Here you can see the ID starting with 00867 but that is the first record of the true path.

So the problem is pure cosmetic in the designer.

Thanks for the patience guys!

Great! Yes, that is currently sadly one of many limitations of the editor. I hope we can improve that in the future to make that less confusing for people!

Have fun!

1 Like