Node dev : getNodeParameter usage?

Ah OK. In this case the node I did create above should do exactly that.

Sorry jan I didn’t expand your code …
Yes, items[i].json.itCode is the good key
So the loop is not necessary : I get a local node parameter value (in its form) by this.getNodeParameter(paramName, 0) and I get input value by this good key, so it’s ok for me :slight_smile:

Last thing jan, you said :

And also there it looks again like you are mixing up parameters and items.

So I’ll never understand why I see so many loops on input items which calls getNodeparameter() each … very confusing for me, and that’s why I had to create this post.
But I won’t care anymore :slight_smile:

Ah no it is important to understand that concept.

The reason is expressions.

So if the following two items get sent into a node:

[
	{
		"json": {
			"name": "Tim"
		}
	},
	{
		"json": {
			"name": "Frank"
		}
	}
]

That data gets received exactly like that by this.getInputData(). I guess so far it is clear.

Ok, now lets add a parameter called “message” to the node and set it to “Hello”. The following data would get returned:

this.getNodeParameter('message', 0) // For the first item => "Hello"
this.getNodeParameter('message', 1) // For the second item => "Hello"

They return the same as the value of the parameter is set to a fixed value which is here “Hello”.

Now lets change the parameter “message” to an expression and then set the value to

Hello {{$json["name"]}}

Now the result would be:

this.getNodeParameter('message', 0) // For the first item => "Hello Tim"
this.getNodeParameter('message', 1) // For the second item => "Hello Frank"

So the {{$json["name"]}} tells n8n to replace it with the value it finds under “name” from the incoming data. As there could be multiple items (and in the above example there are, exactly two) we have to tell it which item it should use to resolve the expression. Therefore the loop and the index. In the first one we tell it to use the data of index 0 which has for “name” the value “Tim” and for the second one we give it the index 1 for the second item which has the value “Frank”.

I hope that makes sense.

Well understood jan, but this cannot suit my case
It could if we could type code in the itCode field value (but we can’t), for example
{{$json["itCode"]}} || AAA-BBB-1111
meaning ‘take the input itCode, and if undefined take this default value’

You can, but you have to write it differently:

{{$json["itCode"] || "AAA-BBB-1111"}}

hey :slight_smile: I’m going to test that, thanks jan !