Referencing data from previous nodes with new syntax $("node-name") only returns first result?

Continuing the discussion from Adding data from previous node to every item of another node:

Describe the problem/error/question

The new syntax only returns the first item. By default, when you drag & drop an item from previous nodes (few nodes back) it will output the following expression:

{{ $(‘HTTP Request’).item.json.result**[0]** }}

@jan posted this example earlier, and while the above reference to first array [0] is clear, removing the reference breaks the expression.

Given example by jan: $(“Webhook”).item.json[“body”][“event”][“event_name”]

Tested: {{ $(‘HTTP Request’).item.json[‘result’][‘account’][‘name’] }} >> does not work, returns undefined.
Test #2: {{ $(‘HTTP Request’).item.json[‘result’][0][‘account’][‘name’] }} works, but returns only first item.

What is the error message (if any)?

No error, just returns the first item. Or if reference to array [0] is removed, expressions return undefined.

If I have understood correctly, pairedItem functitonality should work even if number of items changes during the workflow? Let’s say I am running multiple HTTP nodes where first one returns 60 items and final output will over 1000 items. (Querying DNS records from Cloudflare and start by fetching all zones (domains) then listing all dns records for each zone, so it adds up.

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:

So, the following works: {{ $(‘HTTP Request’).item.json[‘result’][$itemIndex][‘account’][‘name’] }}

Adding $itemIndex to replace the [0] reference fixed it, question is, if this is necessary, why does the drag & drop not default to this format?

EDIT: Did not resolve the issue, it only returns value for first 60 items in order without matching the items, so results for first 60 items are wrong as well. Rest of the records are not matched at all.

What am I missing here? :o

1 Like

Hi @lazmo88, I am sorry you’re having trouble. This doesn’t look like a problem with the expression but rather with the data structure.

Based on your description it seems the result field is an array field from which you want to fetch multiple items. The expressions will however reference an n8n item rather than individual objects in array fields of these n8n items.

Perhaps you simply want to run an Item Lists node immediately after your HTTP Request node to split out the result item? Afterwards you should have one n8n item per item in your result field which should simplify things down the line.