Retrieving the input of a previous node

Describe the problem/error/question

I would need to access the input I had passed to a previous node.
Unfortunately doing $('Node name') doesn’t work as the that node return an array o items and I need only the one that was used go run the previous node.

For example:

Node A (outputs 5 items) → Node B (for each item fetches ~2 items by A.ID) → Current Node (I want to access A.ID, used in B)

What is the error message (if any)?

No error message.

Information on your n8n setup

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

hello @nickfla1-mxm

Can you share the workflow? And is it possible to output the A.id that you have used in the Node B?

1 Like

Hi @barn4k !
Yes, I was having issues sharing the workflow.

This is the workflow, part of it actually. The input to “Get Open PRs” is a list of repository names. “Get PR Events” iterates on every PR from the prev node. I can’t share the actual output since it contains private information.

I need to fetch an info, the PR number, from “Get Open PRs” inside the last node, in particular I need the PR number used as input of “Get PR events”.

Thanks!

The $(‘Node name’) syntax always gives the output of the node you’re referencing. So if you want its input, you need to reference the node before that (since the previous node’s output is the next node’s input).

So if you want the PR number used as input for ‘Get PR events’, you would use something like $('Get Open PRs').item.json.pr_number.

3 Likes

Hi @sirdavidoff !

I tried before but I was confused by the autocomplete not proposing item as a property of $('Get Open PRs') (see screenshot). Indeed your solution works!

image

Thanks for the support!

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