"Set" losing value? Bug?

Hello,

Not sure how to explain…
“Set” is losing the value if more than 1 item is passed through
This is the example:

“Set” picks up the “insertid” field. this is supposed to be used later in the workflow

The “Mysql2” query is supposed to work with that “insertid”

It works for the first item passed but then I get this error:

If i hardcode the insertid it works!!

Am I doing something wrong or is it a bug?

Thank you

I have seen this behavior also with sending emails! Data is lost after first email!

message body:

Emails received:

As you can see, “PRO-131” just vanishes after first email.

Hi @xewonder, this is because your Set node returns only a single item, but subsequent nodes return multiple items.

Now what would happen for an expression like {{ $node["Set"].json["insertId"] }} is that for the first item on your MySQL2 node, n8n would look up the first item on your Set node (which works). For the second item, n8n would look up the second item on your Set node which won’t work and so on.

To avoid this, you would want to use an expression like {{ $item(0).$node["Set"].json["insertId"] }} This ensures that n8n always uses the first item (with index 0) of your Set node, even when processing additional items. $item(0) is documented here.

Hope this helps! Let me know if you run into any trouble with this.

That worked perfectly! thank you so much!

1 Like

Sweet, glad to hear & thanks for confirming!