Bad Expiriences with N8N when try to use $node.item

Describe the problem/error/question

I have postede some question about issues with item and first(). If workflow has just a few nodes or is a simple workflow $node. item work fine but when your worflow is complex and has nodes like sql or mysql with multiplies rows returned and js code I am facing a lot of issues when try to use $node.item, and it forced to me to use $node.first() and that change all logic of my workflow.

Has anyone else faced the same issue?

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
    latest 1.56.2

  • Database (default: SQLite):

  • n8n EXECUTIONS_PROCESS setting (default: own, main):

  • Running n8n via (Docker, npm, n8n cloud, desktop app):
    Docker

  • Operating system:
    ubuntu

If you pass the data through a node that changes the numbre of output, n8n will be confused as to which item to link to


The trick for this is to always pass the data via a new set node each time you pass it through a change in field to prevent these errors

Thanks for confirming my suspicious
 I have a lot of nodes than changes the numbers of outputs, uff
 I have to modify all my workflow :(. it is a shame thaty n8n be to weak handle previous items links

If I understood, what you said is that I have to try that all my nodes return just one output? If that, how handle when use sql or mysql nodes that make a. select * from table and ouput for this node are multiples rows
?

Thanks again for you tip

For now i had to put all my mysql node in another workflow ans call then from my main workflow I know is not the best workaraound but for now is working. This is really weakness of N8N

For complex workflows, you’ll have to know how n8n process data, as you will face the issues eventually.

The easiest approach is to pack all items into one with an Aggregate node, making it easier to work with it.

1 Like

I’ve faced this too, generally when I have some nodes that run for each item and others that only run once. I don’t even bother using .item anymore and just use first() now, unless I know for sure the node outputs multiple items.

I feel like there should be better shorthand for accessing variables, like just as simple as $(‘My Node’).fieldname , whereby if it’s a multi-item node it defaults to return the current item. You could still query for other indexed items by $(‘My Node’)[i].fieldname .

For me, if there’s a binary file it’s always in $binary.data anyway so having the additional complications of doing node.json.first(). seems like unnecessary bloat. You could simply always store the binary in $(‘My Node’)._binary by reserving that special property.

That way, you treat each node as a simple json object or json list by default and it would be so much simpler.

My issue is thant when i use first in a multiple customer process first alway use the first client on the list and I need to use specifi Item process. My solution defnitly is not the best my be the worst but by know is working. This give me a chance to try your solution
Thanks

1 Like

Another thing I have found is that if I consolidate all the items into a code node and then try and access “item” from a later node, I can no longer do it–I get a ‘bad matching’ error.
In that case I have to wire a Set node in between an earlier node and the later node. I’m not sure if that’s the best way to do it, but I can confirm it does work.

Yes I had to do that too in order to solve this issue beside of pur all my sql selector node that retienes mĂșltiples roes in sepĂĄrate workflows.

1 Like

Here’s the translation:

“Sorry for the way I wrote. I didn’t realize. In my case, I had to do the same. I had to create several set nodes. Additionally, I had to move all the MySQL nodes that retrieve many rows into separate workflows and then call them from the main workflow. That’s what I did.”

1 Like

In my case I had an outer loop and inner loop and I also ended up making the inside into a nested workflow to fix my issues.