How to bypass empty IF with a Merge by key

Hi,
image

I am a bit in a pickle now or just having a brain fart, I have 2 IF conditions, where in first one sometimes customer fills in the contact, sometimes not and thus results in empty.

In the second IF, the customer always fills the contact, in the end I need to continue flow by merging the data by key (I cannot use append because customer sometimes can be in both and it duplicates the accounts).

Issue is that if first IF is empty (all customers during this time filled in the contacts), then the merge by key will not work and return empty. Any idea of how to bypass this and allow the flow to continue not being empty and just have the 2 IF data?

Thank you very much.

Hey @Jorge_M!

Were you able to figure out the solution?

I made a small workflow that replicates your concern. In this workflow, I connect Input 1 of the Merge node with the IF node that will always return data. Input 2 of the Merge node is connected to the IF node which may be empty. Can you swap the inputs of the Merge node and let me know if this solves your issue?

Here’s my example workflow:

{
  "nodes": [
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "Name",
              "value": "n8n"
            },
            {
              "name": "website",
              "value": "https://n8n.io"
            }
          ]
        },
        "options": {}
      },
      "name": "Set1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        550,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": []
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        550,
        500
      ]
    },
    {
      "parameters": {},
      "name": "Always filled",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        750,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json[\"age\"]}}",
              "operation": "isEmpty"
            }
          ]
        }
      },
      "name": "Optional",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        740,
        500
      ]
    },
    {
      "parameters": {
        "mode": "mergeByKey",
        "propertyName1": "Name",
        "propertyName2": "Name"
      },
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        1000,
        340
      ],
      "alwaysOutputData": false
    }
  ],
  "connections": {
    "Set1": {
      "main": [
        [
          {
            "node": "Always filled",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "Optional",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Always filled": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Optional": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    }
  }
}
1 Like

Hi @harshil1712,
Thanks, No, I didn’t have much time to spend on n8n :slight_smile: lately. Getting back now. Thanks, will give it a go :).