Need a solution for a loop workflow

I need a solution for my workflow:
Let’s say I have a loop using split in batches. In this loop a node is responsible for getting data using api. But this data needs to be filtered.
After the loop is finished there is an email node that sends an email containing those filtered data.

With older versions of n8n I did it this way: I defined a variable in a function node added before the loop using items[0] = []; And in the loop itself I used another function node to push the filtered data in that variable. And after the loop I could access this variable using $node[“Function”].json[“data”].

But with new versions of n8n this approach doesn’t work.

I wonder how this can be done.

Hey @jellybean,

The old approach should still work, Do you get any errors when you try? Are you able to share the workflow as well?

1 Like

Thanks for the reply.
I cannot share the flow. But I can share the function nodes:

function node before the loop:
items[0] = [];

function node inside the loop:

const data = $node["Function"].json["data"]
const response = $node["Api"].json["output"]["response"];

response.forEach(item => {
  if (...) {

$node["Function"].json["data"] = data;

return items;

And after the loop I could access the data with this expression:

Does the workflow below help? It shows a way to merge multiple executions from a node and it might have what you are missing.


Yes that works.
Thank you very much @Jon


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