Help with Looping

Finding it hard to understand looping…

So this is very basic workflow:

What i would like to do is get the insert happening seperately for each item generated in my code node.

Appreciate all patience and feedback :slight_smile:

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

Hi @Surge.Media

Your issue is that you are refering to the code node in the expressions. You should just use $json.fieldname to refer to the incoming data directly.

2 Likes

Hi @BramKn - thanks for the quick reply. Could you be a bit more specific of what i should be doing or how i should be writing it. I am not sure i am following, or even know how to run this to test it properly, i have ammended the node as follows, but still only getting the first result into my db

Hi @Surge.Media

Not sure why it would not work

Did a quick test with your data and it is working fine:

I am not using set node as it demonstrates the data and I do not have a mysql to test with.

Thank you - i got it working!

2 Likes

@BramKn how would i call values from nodes further back if not by using code.node in the expression ?

It all depends on what you are doing and what you need.
But I personally almost never check data from nodes back (except settings for example with .First() ) I do not like unexpected behaviour so I most often just use merges to get data back together. Also using a subflow helps to simplyfy things with the items and runs of items.

So as an extended example I am trying to use part of the data that is generated before the loop in a node further down the line, like this:

Make sure the data is there at the beginning of the loop in the items you feed into the loop.

All the data is in the node before the loop, what i am having issues with specifically is spool_db_name, which i am trying to use in the last node the mysql one. The first two variables are working fine and are used in the two nodes before the mysql node.