I just don't get the loop node

Describe the problem/error/question

i did plenty of research in this forum and in your documentation, but i fail to understand the loop-node - at all.

i have a workflow, in which one part is to convert google multi-day-events (one event that spans multiple days) into multiple one-day-events.

therefore i came up with the idea to duplicate items, if they are multi day events:

  • one item is converted to a single-day-event
  • one item is reduced by one day

so i have 3 paths:

  1. original single day event (“AlreadySingleDay”)
  2. multi day event, that is reduced to a one day event (“SetEndTime To Start+1”)
  3. multi day event, that is reduced by one day (“Set Start Date to Start +1”)

path 3 is then going back to the start of the 3 paths, path 1 and 2 continue to go on with the workflow.

Now here comes the culprit:
i get several runs of path 1,2 and 3 - and want to combine them all, and continue if all are finished.

Threrefore i use a Loop-Node in the fashion below.

What i expected that would happen:
Each element, that is fed to the loop again would remain there until there are no more elements in the loop, and a total of all elements is then passed on via the loop-branch to the next node.

What acutally happens:
depending on using the Merge at path 1 and 2:
a) with the merge:
it works quite alright, but ocassionally, some elements just are droped from the done-results (deterministically) - this might be a bug?
b) without the merge (individual paths back to the loop node):
i get results up to 2.000 although there are only about 60 results in reality

so, therefore i came up with the two nodes “getAllEventsOfAllIterations” and “Split Out2” where i just ignore all input that is coming from the loop node, and via code extract all items of all iterations of path 1 and 2 (“AlreadySingleDay” and “SingleDayEvents”) So the loop node is basically just there, to wait for all the paths inside to be finished.

What is the error message (if any)?

No error message, but my question is really:
Am i just wrong in the assumptions that the done loop should contain all elements, that are fed back to the loop node, and if all elements within the loop - loop are processed, then the done branch will deliver all those elements?

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

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

Just upgraded to the latest version: 1.103.2 did not change a thing

Hi @Gerhard_Sporer, have you tried to change the ‘Append’ mode in the Merge node to ‘Combine’ mode?
I think it can help you!

well, there is no difference in using that option.

i used fields, that will never be the same, because i do not want to combine the fields, but i want to get mutliple elements.

so, no - it does not help, to use combine.

Hey @Gerhard_Sporer hope all is well. Welcome to the community.

Could you please confirm that the idea of the flow you are looking to build is to retrieve an event from Google Calendar and if this is a multiday event, for example 3 day event, you want to split this event in Google Calendar into 3 single day events. As in, the result of running the flow is 3day event is gone, 3 single day events are added?

yes, thats is exactly what i plan to do, and it almost does exactly that.

But for whatever reason, in the merge, there are sometimes events missing. Although in a deterministic way. Always the same events are lost on the way.

The Merge input amount to 10+5 elements, but only 12 elements are in the output of the merge.

To be honest, i don’t get, why i do neet the merge at all, because i just want all the output of the path 1 and 2 to be added to the done path of the loop.

But when i skip the merge and connect the output of path 1 and 2 directly to the loop - all hell breaks loose, and i get elements in the 1.000s.

and to provide more context:

the main goal ist to have a “calender-sync”. whenever people put an event in their calender named “hotteam” they are part of that days team. So to visualize that we put a summary event (something like “this 6 People are the Team - A,B,C,D,E,F”) every day in a common calender.

The current approach is to get all mathing events of the single persons and all mathing events of the common calender, and then sync them.

All is well, but the multi-day-events just go awry.

What about something like this?

Read Events → check if multiday → split one range into 1 day chunks → create new event

Hi jabbson,

thanks for the input. yes, that would work as well.

but this is not really the problem i have - the workflow as of now is up and running, and very well.

Still, my question in the title of this topic is unanswered. what is the loop node supposed to do?

And why doesn’t it do, what i expect (if i do not use the merge node)

The loop handles a list of items that are passed to it. If rhose items are separate node outputs, they will act like separate loops. You need to merge the items going into it so its a single loop set with x number of items to loop.

Merge mode append, each branch would be a separate input, so it sounds like you would merge those 3 inputs and then pass that into the loop.

hi rhyswynn,

thanks for you input, very much appreciated!

it looks to me, that in my workflow (pasted in first post) i did exactly what you suggested. The input of the loop is the original, and then the outpot of the single node from the NoOp1 into the loop again.

I honestly did not understand your second paragraph. with the merge, i want to aggregate the output of both nodes (“AlreadySingleDay” and “SingleDayEvents”) into a single path of items. But it seems at this point, some items are discarded.

It seems my problem is not so much the loop-node, but the merge, that does not what expected:

“Take whatever comes from input A or input B and output the items. Do not discard any item at all. Do not change any item at all.”

i just want to merge those two paths into one single path.

to illustrate my culprit let me share a pic:

count of items of “Merge”:
input 1: 56 items
input 2: 10 items
output: 62 items → 4 items are missing!

Theese are the settings of the merge node - notice the “keep everything”:
{
“nodes”: [
{
“parameters”: {
“mode”: “combine”,
“fieldsToMatchString”: “id, organizer.email, start.date”,
“joinMode”: “keepEverything”,
“options”: {}
},
“type”: “n8n-nodes-base.merge”,
“typeVersion”: 3.1,
“position”: [
3328,
448
],
“id”: “14249af4-224b-4e51-be1a-6c358d957a67”,
“name”: “Merge”
}
],
“connections”: {
“Merge”: {
“main”: [

]
}
},
“pinData”: {},
“meta”: {
“instanceId”: “1e6d5d6b1bf2784d16333fcefb853a2849efcee5e1ee8afaae83626ba14ad636”
}
}

i suspect the items are discarded, because of the timing of input 1 and input 2.

maybe if there are items in input 2 that arrive after the last input 1 there might be an issue - but i dont see any mentions of timing or “wait for input” or something like that in the documentation.

EDIT: and just a note - i did change the merge settings to “append” again, but there is no difference at all, still 4 items short of my expected behaviour of outputting all inputs unaltered.

Please show the output of this running with append mode enabled. I had this exact issue and append resolved it, there are no other options than the number of inputs for append mode

here you are - i did try append from the start, just converted to combine after the hint from another user:
As you can see:
30 + 11 does not equal 37 - i would like to have all 41 items…

new reply as requested by email-bot, since the issue is still not solved.

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