Problem with sending data to mysql after split out and if node

I am trying to add data in mysql after a split and if node. but I failed.

I am getting this error

Hi @Md_Ashickur_Rahman

This happens because you are using the expression:

{{ $('Split Out').item.json.invoice_no }}

Problem:
After a Split Out, there are multiple items.
n8n cannot determine which item from the “Split Out” node you want to use, so it blocks the execution.

This behavior is exactly aligned with the documentation:

When a node generates multiple items, direct references to another node require an explicit index or the use of the current item.

Correct solution (official documentation):

Golden rule in n8n:
Inside loops (Split Out, IF, etc.), always use $json and never reference another node directly.

Correct (recommended by the documentation):

{{ $json.invoice_no }}

Alternative (only if you really need a specific item):

{{ $('Split Out').item(0).json.invoice_no }}

Warning:
This approach breaks easily if the number of items changes and is not recommended for database inserts.

Thanks for your reply. I am not getting it , how to resolve my issue.

hi @Md_Ashickur_Rahman as said by @tamy.santos you just need to

  • 1/ add a “Loop Over Items“ between your “split out“ and “check invoice_already_in_database“.
  • 2/ in your mysql node “Insert rows in a table“ you change the value to insert from “{{ $(‘Split Out’).item.json.invoice_no }}“ by “{{ $(‘Loop Over Items’).item.json.invoice_no }}“
  • 3/ connect back your node “Insert rows in a table“ to the loop
1 Like

Hi @Md_Ashickur_Rahman !

Could you please explain in more detail which part you’re still not getting? That will help us be more precise in our support.