How To properly LOOP through comments!

Hey, i’m having a hard time to implement this simple loop in my workflow, where i have a list of comments and each one may have/not replies.

Describe the problem/error/question

so i need to pass comments one by one and (loop) to mysql node (insert query) + get the record id (insertId) + now batch insert replies linked with insertId as their parent … and thats it .

it wont loop through all comments (15), it loops only for 3 for no reason

What is the error message (if any)?

No error message :frowning:

Please share your workflow

Information on your n8n setup

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

Hey @Mr_Developer

Your loop is ending prematurely because the 4th comment in your list does not have replies and so within the loop, the “replies” code node returns no items which stops the workflow.

You’ll need to check if this is true and return early back to the loop node if this is the case.

Also consider that you might not need the loop node. This template should also work for your use case.