Merging items after "split in batches"


I have a function that outputs a list of locations, which I use to look up the weather. All the data is supposed to be gathered and run through a template for rendering before going to Slack.

I have a setup like this:

How can I gather all the split data items into a single item?

That can be done like this:


Sweet, thanks!

1 Like

This solution seems kind of arbitrary, as it relies on a known up-front counter, but how do we handle paginated urls, when you don’t know the total number of pages?

Welcome to the community @philipsd6!

That is not correct. The solution does not expect that. It works no matter how many iterations there were.

OK! I posted a new topic for the situation I’m seeing – hope to hear from you there.

As @jan said, it will iterate over the result set until it gets an exception and then just break the iteration and return the result.

If you look at the code it becomes a bit easier to see:

const allData = []

let counter = 0;
do {
  try {
    const items = $items("Increment", 0, counter).map(item => item.json);
    allData.push.apply(allData, items);
  } catch (error) {
    return [{json: {allData}}];  

} while(true);
1 Like

Yes, I see I was off-base in my comment, as it does iterate properly – however, I have noted problems, so I have a new topic opened for my problem – thanks!

this doesnt work for the new code node

@RedPacketSec there’s an updated template for the code node: Merge multiple runs into one | n8n workflow template

1 Like

thanks will have a look at it

ah perfect this is exactly what i needed! Thank you so much

1 Like

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