Use either available value of not directly connected nodes

Hi. Sometimes, I wouldn’t know which variable is going to be used in a node and need to somehow set both. In the previous versions of n8n, I would just put them next to each other like this $node["Fetch account ID by domain name"].json["data"][0].id$node["Create a company account in Salesloft"].json["data"]["id"] and n8n would take whichever one is available. After this was changed, I’ve been struggling a lot and it created so much problems for us

I’ve tried expressions like {{ $node["Fetch account ID by domain name"].runIndex === 0 ? $node["Fetch account ID by domain name"].json["data"][0]["id"] : $node["Create a company account in Salesloft"].json["data"]["id"] }}
but it would work in some cases and fail in another with an error message [No data found for item-index: "0"]
The worst part is that the flow still continues and doesn’t produce an error so I never know if it works properly or not unless manually tested.

My idea here is to check if a company already exists in Salesloft. If yes, then take the ID of it and create a note. If not, then create a company and take it’s ID and add a note. These nodes are not directly connected to the one creating note. And the structure of the variable is a bit different since one of them does a search and it’s going to be a [0] result.

What’s the best way to go about this?

  • n8n version: 1.18.1

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

hello @Artego

No, it didn’t do that, it just concatenated both values into one. Like _value (_ - is a space that was an actual null value) and didn’t check for the errors

That one should work:

{{ $ || $[0].id }}

to use IF/Filter/Edit Fields nodes :slight_smile:

Can you provide a sample for the Get all contact fields node?

Hey. Thank you. The solution you offered only works if the node is directly connected to the other 2.

As far as I know, you can’t refer to the node, that hasn’t been executed, so you only may refer to the relative $json link. Or, you may create a “proxy” node that will be executed either way and refer to it. Example attached:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.