IF node: How do I create a condition to check if the current record already exist?

I got addicted with the possibilities but got stuck with likely just a simple logic twist in my mind. Someone can help to unwind my brain please?

  • Using the brandfetch sample workflow I need to add a simple IF clause to decide whether to
    • append (a new record to the table)
    • or update (an existing) record in Airtable.

How do I create a condition to check if the current record already exist?
Using the “name” would be good enough but whatever I condition I use I end up with “false” getting and a new record created (append flow runs after IF clause)

That is great to hear!

Yes what you want to do is sadly not that simple. Here how it can be done:

And the workflow:

{
  "nodes": [
    {
      "parameters": {
        "domain": "n8n.io"
      },
      "name": "Brandfetch",
      "type": "n8n-nodes-base.Brandfetch",
      "position": [
        400,
        300
      ],
      "typeVersion": 1,
      "credentials": {
        "brandfetchApi": ""
      }
    },
    {
      "parameters": {
        "operation": "company",
        "domain": "={{$node[\"Brandfetch\"].parameter[\"domain\"]}}"
      },
      "name": "Brandfetch1",
      "type": "n8n-nodes-base.Brandfetch",
      "position": [
        600,
        300
      ],
      "typeVersion": 1,
      "credentials": {
        "brandfetchApi": ""
      }
    },
    {
      "parameters": {
        "operation": "append",
        "application": "",
        "table": "Table 1",
        "options": {}
      },
      "name": "Airtable",
      "type": "n8n-nodes-base.airtable",
      "position": [
        1660,
        100
      ],
      "typeVersion": 1,
      "credentials": {
        "airtableApi": ""
      }
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.id }}",
              "operation": "isEmpty"
            }
          ],
          "boolean": []
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1200,
        100
      ]
    },
    {
      "parameters": {
        "mode": "keepKeyMatches",
        "propertyName1": "fields.Name",
        "propertyName2": "Name"
      },
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        1000,
        100
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "mode": "passThrough",
        "output": "input2"
      },
      "name": "Merge1",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        1460,
        100
      ]
    },
    {
      "parameters": {
        "mode": "passThrough",
        "output": "input2"
      },
      "name": "Merge2",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        1460,
        300
      ]
    },
    {
      "parameters": {
        "operation": "update",
        "application": "",
        "table": "Table 1",
        "id": "={{$node[\"Merge\"].json[\"id\"]}}",
        "options": {}
      },
      "name": "Airtable1",
      "type": "n8n-nodes-base.airtable",
      "position": [
        1660,
        300
      ],
      "typeVersion": 1,
      "credentials": {
        "airtableApi": ""
      }
    },
    {
      "parameters": {
        "operation": "list",
        "application": "",
        "table": "Table 1",
        "additionalOptions": {}
      },
      "name": "Airtable2",
      "type": "n8n-nodes-base.airtable",
      "typeVersion": 1,
      "position": [
        800,
        50
      ],
      "credentials": {
        "airtableApi": ""
      }
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "Name",
              "value": "={{$node[\"Brandfetch1\"].json[\"name\"]}}"
            },
            {
              "name": "Icon URL",
              "value": "={{$node[\"Brandfetch\"].json[\"icon\"][\"image\"]}}"
            },
            {
              "name": "Logo URL",
              "value": "={{$node[\"Brandfetch\"].json[\"logo\"][\"image\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "position": [
        800,
        300
      ],
      "typeVersion": 1
    }
  ],
  "connections": {
    "Brandfetch": {
      "main": [
        [
          {
            "node": "Brandfetch1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Brandfetch1": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Merge2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge1": {
      "main": [
        [
          {
            "node": "Airtable",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge2": {
      "main": [
        [
          {
            "node": "Airtable1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Airtable2": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          },
          {
            "node": "Merge1",
            "type": "main",
            "index": 1
          },
          {
            "node": "Merge2",
            "type": "main",
            "index": 1
          }
        ]
      ]
    }
  }
}

@jan, thanks! Get some rest. :wink:

I believe that’s going to make things really complex and hard to maintain. Isn’t there a node that could stringify an object and have the IF node “comparing against it”?

So the flow could be: Brandfetch >> Set >> Get (Data/ID as Object from target) & Stringify >> IF (to Compare > …

I could imagine, such a Get (&Compare) node would also impact execution time, reduce server ressources and improve readability & maintainabillity of larger “beasts” over time.

No stress, at this time I am just playing to understand the options I got to apply some magic here and there.