I cannot deal with if node

Hey,

I am trying to accomplish to go throw nodes if notion return 0 items. But n8n cannot answer 0==0 it no say True and not say False.

In my understanding it should go to discord node, shouldn’t it?

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        280,
        0
      ],
      "disabled": true
    },
    {
      "parameters": {
        "url": "https://koronawirus-api.herokuapp.com/api/covid-vaccinations-tests/daily",
        "options": {}
      },
      "name": "Get data",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        490,
        300
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": "51041012-9664-43f8-8237-b91d26f87ea9",
        "returnAll": true,
        "options": {
          "filter": {
            "multipleCondition": {
              "condition": {
                "and": [
                  {
                    "key": "Projekt|select",
                    "condition": "equals",
                    "selectValue": "Covid report"
                  },
                  {
                    "key": "Additional information|rich_text",
                    "condition": "equals",
                    "richTextValue": "={{$json[\"reportDate\"].substr(0,10)}}"
                  },
                  {
                    "key": "Return code|number",
                    "condition": "equals"
                  }
                ]
              }
            }
          }
        }
      },
      "name": "Check if already got",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        690,
        300
      ],
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {
        "webhookUri": "https://discord.com/api/webhooks/904141367670865991/AaIq0nLkHRSOu0QYSXlqxPOQ3Cc5Tk8H26uvLK09zNfXRgDBfe4-NYijgiCG9Va8ja0i",
        "text": "=***Dear <@&906366284982280213> CORONAVIRUS REPORT:***\n\n{{$node[\"Get data\"].json[\"reportDate\"].substr(0,10)}} (__All time__)\n**Infection:** {{$node[\"Get data\"].json[\"today\"][\"infections\"][\"newInfections\"]}} (__{{$node[\"Get data\"].json[\"general\"][\"infections\"][\"infections\"]}}__)\n**Deaths:** {{$node[\"Get data\"].json[\"today\"][\"infections\"][\"newDeaths\"]}} (__{{$node[\"Get data\"].json[\"general\"][\"infections\"][\"deaths\"]}}__)\n**Vaccinations (first doses):** {{$node[\"Get data\"].json[\"today\"][\"vaccinations\"][\"firstDoses\"]}} (__{{$node[\"Get data\"].json[\"general\"][\"vaccinations\"][\"firstDoses\"]}}__)\n**Vaccinations (second doses):** {{$node[\"Get data\"].json[\"today\"][\"vaccinations\"][\"secondDoses\"]}} (__{{$node[\"Get data\"].json[\"general\"][\"vaccinations\"][\"secondDoses\"]}}__)"
      },
      "name": "Push data",
      "type": "n8n-nodes-base.discord",
      "typeVersion": 1,
      "position": [
        1100,
        280
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "databaseId": "51041012-9664-43f8-8237-b91d26f87ea9",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Name|title",
              "title": "=Coronavirus report from {{$node[\"Get data\"].json[\"reportDate\"].substr(0,10)}} pushed to discord server!"
            },
            {
              "key": "Additional information|rich_text",
              "textContent": "={{$node[\"Get data\"].json[\"reportDate\"].substr(0,10)}}"
            },
            {
              "key": "Projekt|select",
              "selectValue": "53bda0cd-99d6-4c98-a512-bff3c7c01176"
            },
            {
              "key": "Return code|number"
            }
          ]
        }
      },
      "name": "Log data",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        1310,
        280
      ],
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "mode": "custom",
              "cronExpression": "0 */1 * * * *"
            }
          ]
        }
      },
      "name": "Cron",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        300,
        300
      ]
    },
    {
      "parameters": {},
      "name": "Error Trigger",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [
        470,
        -10
      ]
    },
    {
      "parameters": {
        "webhookUri": "https://discord.com/api/webhooks/814217605581373480/1n0tSrP1w0a_ETZhYWLFjMsry2Z8iPDTVrKAW6chBkerJD50YvBT0SJwsFFfuSYIzc87",
        "text": "=**!!WORKFLOW ERROR!!**\nWorkflow name: {{$json[\"workflow\"][\"name\"]}}\nError message: {{$json[\"execution\"][\"error\"][\"message\"]}}\nLink to workflow: https://n8n.hryszko.dev/workflow/{{$json[\"workflow\"][\"id\"]}}\nLink to execution: {{$json[\"execution\"][\"url\"]}}\nLast good node: {{$json[\"execution\"][\"lastNodeExecuted\"]}}."
      },
      "name": "Error info",
      "type": "n8n-nodes-base.discord",
      "typeVersion": 1,
      "position": [
        650,
        -110
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "databaseId": "51041012-9664-43f8-8237-b91d26f87ea9",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Projekt|select",
              "selectValue": "53bda0cd-99d6-4c98-a512-bff3c7c01176"
            },
            {
              "key": "Return code|number",
              "numberValue": 1
            },
            {
              "key": "Name|title",
              "title": "={{$json[\"execution\"][\"error\"][\"message\"]}}"
            }
          ]
        },
        "blockUi": {
          "blockValues": [
            {
              "richText": true,
              "text": {
                "text": [
                  {
                    "text": "Workflow name: ",
                    "annotationUi": {
                      "bold": true
                    }
                  },
                  {
                    "text": "={{$json[\"workflow\"][\"name\"]}}",
                    "annotationUi": {}
                  }
                ]
              }
            },
            {
              "richText": true,
              "text": {
                "text": [
                  {
                    "text": "Error message: ",
                    "annotationUi": {
                      "bold": true
                    }
                  },
                  {
                    "text": "={{$json[\"execution\"][\"error\"][\"message\"]}}",
                    "annotationUi": {}
                  }
                ]
              }
            },
            {
              "richText": true,
              "text": {
                "text": [
                  {
                    "text": "Link to workflow: ",
                    "annotationUi": {
                      "bold": true
                    }
                  },
                  {
                    "text": "=https://n8n.hryszko.dev/workflow/{{$json[\"workflow\"][\"id\"]}}",
                    "isLink": true,
                    "textLink": "=https://n8n.hryszko.dev/workflow/{{$json[\"workflow\"][\"id\"]}}",
                    "annotationUi": {}
                  }
                ]
              }
            },
            {
              "richText": true,
              "text": {
                "text": [
                  {
                    "text": "Link to execution:",
                    "annotationUi": {
                      "bold": true
                    }
                  },
                  {
                    "text": "={{$json[\"execution\"][\"url\"]}}",
                    "isLink": true,
                    "textLink": "={{$json[\"execution\"][\"url\"]}}",
                    "annotationUi": {}
                  }
                ]
              }
            },
            {
              "richText": true,
              "text": {
                "text": [
                  {
                    "text": "Last good node: ",
                    "annotationUi": {
                      "bold": true
                    }
                  },
                  {
                    "text": "={{$json[\"execution\"][\"lastNodeExecuted\"]}}",
                    "annotationUi": {}
                  }
                ]
              }
            }
          ]
        }
      },
      "name": "Push error to logs",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        650,
        30
      ],
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{$items(\"Check if already got\").length}}",
              "operation": "equal"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        890,
        300
      ]
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1090,
        460
      ]
    }
  ],
  "connections": {
    "Get data": {
      "main": [
        [
          {
            "node": "Check if already got",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if already got": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Push data": {
      "main": [
        [
          {
            "node": "Log data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cron": {
      "main": [
        [
          {
            "node": "Get data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Error Trigger": {
      "main": [
        [
          {
            "node": "Error info",
            "type": "main",
            "index": 0
          },
          {
            "node": "Push error to logs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Push data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Thanks in advance!

The problem is that by default, when and the node does not return data, the execution stops. To override this behavior, go to the node settings and set Always Output Data to true.

2 Likes

So it’s not working for me ;/

I removed no op node but with this block it did not work as well ;/

You have to do that in the Notion node (Check if already got), not in the IF node.

Ok, but how 3==0?

Is there only one output on the if node or is there multiple?

It’s not. What you see there is the expression referencing the first item of the Get Data node - For testing purposes. But I assume that you have more than one item. If you open the IF node at the top, you can see how many items went to the true path and how many went to the false path. See the image below.

1 Like

Hey @Shirobachi! I’ve faced same isue today and solved it with following boolean expression in IF node:

{{Object.keys($items("PutHereTheNameOfYourPossiblyResultlessNode")[0]["json"]).length > 0}}

So you were right, I changed flag run once to true

Now like that node called check if already got has flagged always output == true so even when it has 0 items length is 1 or more

What I am trying to accomplish is to go throw if node only if notion check if already got has no items

Basically I check official API about covid cases and push them to discord and to notion logs, next time check logs if I can find any log from Today if not then push otherwise stop.

Maybe is an easier way to do it, so I explained what I am doing, here is the newest nodes in JSON:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://koronawirus-api.herokuapp.com/api/covid-vaccinations-tests/daily",
        "options": {}
      },
      "name": "Get data",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        460,
        630
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": "51041012-9664-43f8-8237-b91d26f87ea9",
        "returnAll": true,
        "options": {
          "filter": {
            "multipleCondition": {
              "condition": {
                "and": [
                  {
                    "key": "Projekt|select",
                    "condition": "equals",
                    "selectValue": "Covid report"
                  },
                  {
                    "key": "Additional information|rich_text",
                    "condition": "equals",
                    "richTextValue": "={{$json[\"reportDate\"].substr(0,10)}}"
                  },
                  {
                    "key": "Return code|number",
                    "condition": "is_empty"
                  }
                ]
              }
            }
          }
        }
      },
      "name": "Check if already got",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        660,
        630
      ],
      "executeOnce": false,
      "alwaysOutputData": true,
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {
        "webhookUri": "https://discord.com/api/webhooks/904141367670865991/AaIq0nLkHRSOu0QYSXlqxPOQ3Cc5Tk8H26uvLK09zNfXRgDBfe4-NYijgiCG9Va8ja0i",
        "text": "=***Dear <&906366284982280213> CORONAVIRUS REPORT:***\n\n{{$node[\"Get data\"].json[\"reportDate\"].substr(0,10)}} (__All time__)\n**Infection:** {{$node[\"Get data\"].json[\"today\"][\"infections\"][\"newInfections\"]}} (__{{$node[\"Get data\"].json[\"general\"][\"infections\"][\"infections\"]}}__)\n**Deaths:** {{$node[\"Get data\"].json[\"today\"][\"infections\"][\"newDeaths\"]}} (__{{$node[\"Get data\"].json[\"general\"][\"infections\"][\"deaths\"]}}__)\n**Vaccinations (first doses):** {{$node[\"Get data\"].json[\"today\"][\"vaccinations\"][\"firstDoses\"]}} (__{{$node[\"Get data\"].json[\"general\"][\"vaccinations\"][\"firstDoses\"]}}__)\n**Vaccinations (second doses):** {{$node[\"Get data\"].json[\"today\"][\"vaccinations\"][\"secondDoses\"]}} (__{{$node[\"Get data\"].json[\"general\"][\"vaccinations\"][\"secondDoses\"]}}__)"
      },
      "name": "Push data",
      "type": "n8n-nodes-base.discord",
      "typeVersion": 1,
      "position": [
        1090,
        630
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "databaseId": "51041012-9664-43f8-8237-b91d26f87ea9",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Name|title",
              "title": "=Coronavirus report from {{$node[\"Get data\"].json[\"reportDate\"].substr(0,10)}} pushed to discord server!"
            },
            {
              "key": "Additional information|rich_text",
              "textContent": "={{$node[\"Get data\"].json[\"reportDate\"].substr(0,10)}}"
            },
            {
              "key": "Projekt|select",
              "selectValue": "53bda0cd-99d6-4c98-a512-bff3c7c01176"
            }
          ]
        }
      },
      "name": "Log data",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        1300,
        630
      ],
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "mode": "custom",
              "cronExpression": "0 */1 * * * *"
            }
          ]
        }
      },
      "name": "Cron",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        270,
        630
      ]
    },
    {
      "parameters": {},
      "name": "Error Trigger",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [
        460,
        320
      ]
    },
    {
      "parameters": {
        "webhookUri": "https://discord.com/api/webhooks/814217605581373480/1n0tSrP1w0a_ETZhYWLFjMsry2Z8iPDTVrKAW6chBkerJD50YvBT0SJwsFFfuSYIzc87",
        "text": "=**!!WORKFLOW ERROR!!**\nWorkflow name: {{$json[\"workflow\"][\"name\"]}}\nError message: {{$json[\"execution\"][\"error\"][\"message\"]}}\nLink to workflow: https://n8n.hryszko.dev/workflow/{{$json[\"workflow\"][\"id\"]}}\nLink to execution: {{$json[\"execution\"][\"url\"]}}\nLast good node: {{$json[\"execution\"][\"lastNodeExecuted\"]}}."
      },
      "name": "Error info",
      "type": "n8n-nodes-base.discord",
      "typeVersion": 1,
      "position": [
        640,
        220
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "databaseId": "51041012-9664-43f8-8237-b91d26f87ea9",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Projekt|select",
              "selectValue": "53bda0cd-99d6-4c98-a512-bff3c7c01176"
            },
            {
              "key": "Return code|number",
              "numberValue": 1
            },
            {
              "key": "Name|title",
              "title": "={{$json[\"execution\"][\"error\"][\"message\"]}}"
            }
          ]
        },
        "blockUi": {
          "blockValues": [
            {
              "richText": true,
              "text": {
                "text": [
                  {
                    "text": "Workflow name: ",
                    "annotationUi": {
                      "bold": true
                    }
                  },
                  {
                    "text": "={{$json[\"workflow\"][\"name\"]}}",
                    "annotationUi": {}
                  }
                ]
              }
            },
            {
              "richText": true,
              "text": {
                "text": [
                  {
                    "text": "Error message: ",
                    "annotationUi": {
                      "bold": true
                    }
                  },
                  {
                    "text": "={{$json[\"execution\"][\"error\"][\"message\"]}}",
                    "annotationUi": {}
                  }
                ]
              }
            },
            {
              "richText": true,
              "text": {
                "text": [
                  {
                    "text": "Link to workflow: ",
                    "annotationUi": {
                      "bold": true
                    }
                  },
                  {
                    "text": "=https://n8n.hryszko.dev/workflow/{{$json[\"workflow\"][\"id\"]}}",
                    "isLink": true,
                    "textLink": "=https://n8n.hryszko.dev/workflow/{{$json[\"workflow\"][\"id\"]}}",
                    "annotationUi": {}
                  }
                ]
              }
            },
            {
              "richText": true,
              "text": {
                "text": [
                  {
                    "text": "Link to execution:",
                    "annotationUi": {
                      "bold": true
                    }
                  },
                  {
                    "text": "={{$json[\"execution\"][\"url\"]}}",
                    "isLink": true,
                    "textLink": "={{$json[\"execution\"][\"url\"]}}",
                    "annotationUi": {}
                  }
                ]
              }
            },
            {
              "richText": true,
              "text": {
                "text": [
                  {
                    "text": "Last good node: ",
                    "annotationUi": {
                      "bold": true
                    }
                  },
                  {
                    "text": "={{$json[\"execution\"][\"lastNodeExecuted\"]}}",
                    "annotationUi": {}
                  }
                ]
              }
            }
          ]
        }
      },
      "name": "Push error to logs",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        640,
        360
      ],
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {
        "functionCode": "console.log(items.length);\n\nreturn items;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        860,
        630
      ]
    }
  ],
  "connections": {
    "Get data": {
      "main": [
        [
          {
            "node": "Check if already got",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if already got": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Push data": {
      "main": [
        [
          {
            "node": "Log data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cron": {
      "main": [
        [
          {
            "node": "Get data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Error Trigger": {
      "main": [
        [
          {
            "node": "Error info",
            "type": "main",
            "index": 0
          },
          {
            "node": "Push error to logs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Push data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

@RawmanGrey Thanks, I might use it <3

You should not have changed this to true.

Add an IF node after the Notion Node (Check if already got). In the Notion Node (Check if already got), set the parameter Always output data to true. In the IF node, use a boolean condition with an expression using the length of the input. That way, when Check if already got does not return items, the flow will go through the true path in the IF node.

Check the example workflow below. Notice that I’m using a function node to simulate the Notion node (Check if already got) in your example.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        440,
        890
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [],
          "boolean": [
            {
              "value1": "={{ Object.keys($node[\"Function1\"].json).length === 0 ? false : true}}"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1010,
        890
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {}\n  }\n]"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        710,
        890
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1350,
        800
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function1": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
2 Likes