Data is undefined in expressions

I’ve tried a few things to get data into my hubspot GET here, but no matter how I structure the data one of the values is undefined.

If I send in the data using merge like this (simplified, but correct structure):

  {
    "vid": 125551,
    "properties": {
      "email": {
        "value": "[email protected]"
      }
    }
  },
  {
    "code": 1236
  }
]

Then the “code” is undefined. If I swap the order and send like this:

  {
    "code": 1236
  },
  {
    "vid": 125551,
    "properties": {
      "email": {
        "value": "[email protected]"
      }
    }
  }
]

Then “value” (which is the email) is undefined.

No idea why this is happening. I noticed this also happens when I try to use data from 1 node before and 2 nodes before. One is always undefined.

No idea what to try next. There must be something fundamentally wrong with how I’m using n8n

When I just input {{$json}} as an expression, it seems to show an object in [] that doesn’t contain the second part of that array. I’ve tried array notation like {{ $json[1].code }}, but that is undefined also.

Hi @jmr123 :wave:

Can you also fill out the following template:

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

Could you also share your workflow with us? Additionally, if you use the $("<node-name>") syntax in the expression editor, does this help you select the value?

I’m using n8n cloud with all the default settings and version 1.0.5. I’m on MacOS.

I think I have a fundamental question about n8n. Am I supposed to be able to get data from any previous node in later nodes? For example, can I get data using the $("<node-name>") syntax from, say, node 2 in node 7? Are there any limits to this?

I believe I sorted out the issue above though. After MANY attempts, I eventually came up with something like this {{ $('Merge').all()[0].json.properties.email.value }}. The .all()[0] was the key thing. I wasn’t aware of the all expression and that that’s where I could target a specific object in the array.

1 Like

Hi @jmr123 :wave: You should be able to get data from Node 2 and use it in Node 7 as per your example with that syntax :+1: And thanks so much for posting your solution to this, too :bowing_man:

So the real trick here is this:

{{ $('checkIf').item.json.properties.email.value}}

where checkIf is a node not immediate connected to the one you’re editing. You need to use this format instead of

{{ $('checkIf').all()[0].json.properties.email.value }}

because if your previous node send in more than one item, this would use the data for the first item 3 times instead of the specific data for each item pulled from checkIf.

This was a massive amount of frustration for me, but figured it out and hope this saves someone’s day in the future.

2 Likes

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