Nested loop node is not working as expected when its run for the second time

Hello everyone,
I am running n8n locally on my laptop using Docker and am currently developing a workflow that listens for incoming emails, downloads an attached Excel file, and extracts data from it.
The Excel file contains program schedules for a TV channel over one year:

  • Each sheet represents one month
  • Each month contains multiple days
  • Each day has its own program schedule
    Workflow Logic:
  • The first loop iterates through each sheet (month)
  • The second loop iterates through each day within a month and extracts that day’s program schedule
    Problem:
  • The workflow works correctly for the first month and extracts the data as expected.
  • When processing the second month, the data from the first loop is still extracted correctly.
  • However, the data passed into the second loop immediately goes to the “Done” branch, which causes unexpected behavior.
  • As a result, I cannot extract the program schedules for the second month.
    Question:
  • I am considering using a sub-workflow to solve this issue, but I am unsure:
    Where should I place the “Execute Sub-Workflow” node in my current workflow?
    Are there any alternative approaches that would be more suitable for this scenario?
    Thank you very much for your time and help. I would really appreciate any guidance or suggestions.

Describe the problem/error/question

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

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

I’ve also observed this behavior with one of the members in my community.

@TrinhNhatHuy Would you be so kind to pin some data to your nodes so I can replicate this on my end without having to connect to any data source, please?

@Jon This is likely a bug.

1 Like

@solomon thank you for your help. Im very willing to provide you as much information as i can. Please tell me if you need any further infor.

Hey @TrinhNhatHuy and @solomon !

Isn’t this the “classic” nested loop in smae workflow ?(can’t test since am am not at PC)…

But found this topic from Jon where explains a “trick” about this… but the recommended way still remains the subworkflow.

A summary, “Reset” option in the 2nd loop(inner), and reference to the last node name that runned from outer loop.

Eg : expression in Reset option

{{ $prevNode.name == ‘Group programs by days’ }}

Assuming that was the last runned node in the 1st loop.

Cheers!

3 Likes

Very interesting! Yes, that seems to be the case.

Try this solution, @TrinhNhatHuy

2 Likes

@Parintele_Damaskin and @solomon thank you so much, i have successfully solved my problem.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.