Aggregate loop items

Describe the issue/error/question

I’m creating a flow that send serial numbers (using crypto node) to my customers.

As the data entries the flow, it comes in a single purchase item and i need to break it in X items as they choose how many they want. After that I put every single serial number in a google sheets with the customer data associated. And in the end, I want to send those serial number to my customer by e-mail, like a transactional e-mail.

I’ve created a loop that does almost everything that I need. Dont know if thats was the best solution, but it worked. But the issue here is that I need to sent them all the serials generated by the flow. I cant figure out how to aggregate them and put int the email.

Please share the workflow

Information on your n8n setup

  • n8n version: 0.195.5
  • Database you’re using (default: SQLite):
  • Running n8n with the execution process own
  • Running n8n via [Docker]:

Hi @Fernando_Arata, welcome to the community :tada:

You could use a bit of custom code to merge your items following a loop. Check out this example:

You could then write your results (for example) in a spreadsheet file before sending out your email.


Thanks for the fast reply @MutedJam. Gonna test and back with the results as soon as I can.

You’re most welcome. You’d just need to make sure to update the name of the node in the code snippet (it’s currently set to HTTP Request, but you probably want to use something like Crypto1 instead).

@MutedJam I understood the logic but I there an issue before entering the loop.

My workflow receives this data

“Hora do pagamento”: “03/10/2022 18:06:25”,
“Nome do Cliente”: “Fernando”,
“Email do Cliente”: “[email protected]”,
“Quantity”: “5”

It’s a single item with the quantity being the number of serials it must generate/document on sheets/send to the customer.

How can i transform this single item in 5 or N items?

Oh, this would also require a bit of custom code (or other trickery) as n8n nodes would by default run their logic once for each item present. Or in other words, if one item goes into a node, most of the item one item will come out of the node.

One exception to this would be the Function node. This always runs exactly once, no matter how many items it receives. It can, however, output as many items as you want. So if you want to return a number of items equal to the Quantity field from your example data, a workflow like this would do the job:

You wouldn’t need the loop in this case as a n8n’s Crypto node will run once for each item anyway:

1 Like

Thanks again for the response. Will try soon.

1 Like