Difference from Records

Hi everyone, I wanted to know if there is a function that returns me the two records marked by taking two results of two functions as you can see in the images

Hey @marconte!

Do you want to return only a certain result? If yes, you can use the IF node to check for the value and return them.

1 Like

let me explain: I have two functions, one gives me 6 records and the other gives me 8 records all the same is it possible through a difference function for example to have those two more records?

In that case you can use the Merge node.

1 Like

i tried merge but it doesn’t return the two extra records

Hey @marconte!

Below is an example that might help.

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      id: 1,\n      name: \"Jim\"\n    }\n  },\n  {\n    json: {\n      id: 2,\n      name: \"Stefan\"\n    }\n  },\n  {\n    json: {\n      id: 3,\n      name: \"Hans\"\n    }\n  },\n  {\n    json: {\n      id: 4,\n      name: \"Fourth\"\n    }\n  },\n  {\n    json: {\n      id: 5,\n      name: \"Fifth\"\n    }\n  }\n];"
      },
      "name": "Mock Data1",
      "type": "n8n-nodes-base.function",
      "position": [
        800,
        250
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      id: 1,\n      name: \"Jim\"\n    }\n  },\n  {\n    json: {\n      id: 2,\n      name: \"Stefan\"\n    }\n  },\n  {\n    json: {\n      id: 3,\n      name: \"Hans\"\n    }\n  }\n];"
      },
      "name": "Mock Data",
      "type": "n8n-nodes-base.function",
      "position": [
        800,
        400
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "mode": "removeKeyMatches",
        "propertyName1": "id",
        "propertyName2": "id"
      },
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        1020,
        330
      ]
    }
  ],
  "connections": {
    "Mock Data1": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mock Data": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    }
  }
}

Remember to connect the node which contains the extra values to Input 1 of the Merge node, and the other Function node to Input 2.

1 Like

no result used id for metching

Does the output from the Function3 node contain all the items and the output from the Function4 contain only duplicates? Remember you need to connect the node that contains all the items to the Input 1 and the node that contains only duplicates to Input 2.

1 Like

ok now node 4 has all the elements (9 records) and node 3 has 6 records but the result it gives me is 9 records of node 4
4

finally solved, the error was that I put in the property input β€œ{{$ node [” Function4 β€œ]. json [” id β€œ]}}” instead of the id, thanks very kind

Can you share the data with the proper structure that you receive? It is a bit difficult to replicate the issue without having the actual data. If it contains sensitive information, you can send them via a direct message.

1 Like

It should work as long as the Merge node is using the correct values for comparision.

1 Like

ok send in private message

Ah yes, you have to pass on the key and not the value. I am happy it now working for you!

Have fun :tada: