Using the output of a node as the value of a parameter in another node

Hello!

I’m creating some custom nodes, and I would like to know if it is possible to code the value of the parameter of a node in order to make it use the output from another node.

I’m going to try to exemplify what I mean. Let’s imagine the following workflow:

Start > custom-node-1 > custom-node-2 > custom-node-3

Now let’s imagine that custom-node-3 has a parameter called “Pancakes”, and the output of custom-node-1 is what we could consider “Pancake ingredients”.

I want to set the value of Pancakes to “Pancake ingredients” (i.e. the output of custom-node-1), and I want to make it in the code of custom-node-3. Using an expression in the UI is not an option in this case; it may be possible just to increase the quantity of “ingredients” (e.g. adding the output from another node), but I need to initialize the value of the parameter “Pancakes” with the output from custom-node-1 (“Pancake ingredients”).

Is that possible?

I tried something like the following in the code of custom-node-3, but it seems to be invalid code:

this.getNodeParameter('pancake', 0) = this.evaluateExpression('{{$node["custom-node-1"].json}}', 0)

And secondly, another question somehow related to the previous one:

Let’s consider this code:

this.evaluateExpression('{{$node["custom-node-1"].json}}', 0)

How would you make the node name dynamic? Let’s say that we rename “custom-node-1” to “renamed-custom-node-1”. In the n8n UI the expression is updated automatically with the new name, but what if you need to update the name in the code of a custom node?

Thank you in advance :slightly_smiling_face:

Hey @JKN, welcome to the community!

I want to set the value of Pancakes to “Pancake ingredients” (i.e. the output of custom-node-1), and I want to make it in the code of custom-node-3. Using an expression in the UI is not an option in this case; it may be possible just to increase the quantity of “ingredients” (e.g. adding the output from another node), but I need to initialize the value of the parameter “Pancakes” with the output from custom-node-1 (“Pancake ingredients”).

If you want to do something with the value coming in from a previous node there is no need to specify a parameter. You can simply read the input data in your code and do something with it.

const items = this.getInputData(); should give you the items your previous node has returned.

Hi @MutedJam , thank you for your answer!

I’m afraid I was not clear enough with the description of the issue. I need to use a parameter in “custom-node-3” because its value may be modified in the UI (manually adding “new ingredients” in my example). Nevertheless its value needs to be initialised with the output of “custom-node-1”.

The problem I see with this.getInputData() is that it only refers to the input data of the node itself, which is the output of the node that goes immediately before (“custom-node-2” in my example). Nevertheless I need the output from a node positioned more than one node before: In my previous example, “custom-node-3” needs the output from “custom-node-1”; “custom-node-2” is in the middle, so this.getInputData() seems to not be useful in this case.

That’s also the reason by which I’m using expressions instead of just referencing the input data of the node.

I do have the exact same question. Let me try to clarifiy it:

  1. Node 1 : contains List with two items [{‘project’:‘a’}, {‘project’:‘b’}]
  2. Node 2: Runs a request against any for example for the project a it will return 5 and for the project b it will return 10 messages.
  3. Node 3: For each original item (project a=5 messages) and (project b=10) messages, i want to insert them in any database but i need to have the original information from Node 1 passed to Node 3. It seems like when referencing the Node 1 via {{$node[“Node 1”].json[“project”]}} will not give me the right information.

I found a solution to my specific case by setting the default value of the parameter “Pancake” (custom-node-3) to ={{$node["custom-node-1"].json}} (don’t forget to use the equal sign at the beginning of the expression).

I will mark this post as the solution to this thread if no staff member flags this answer as non-recommended in the following hours.