I’m trying to use Code by Zapier to return multiple objects so that the following steps will execute for each item in the array. The docs say this should work but I’m having issues.
I expected that when I set up an email action in the next step, it would send emails to all three addresses. However, only the first email gets sent. The subsequent steps seem to ignore the other objects in my array.
What am I missing here? Is there a specific way I need to format the output or configure the next step to handle multiple items?
Indeed, what you’re encountering with Zapier is expected behavior. When dealing with arrays, Zapier only processes the first element, treating the entire array as a single output. In my experience, the most effective solution is to ensure each item is processed individually. One approach is to configure your return to use single objects rather than arrays. Alternatively, consider using a webhook or a similar mechanism to send individual records into Zapier. This change simplifies the data handling and allows for effective processing of multiple items in subsequent steps.
Yeah, Zapier’s array processing is a nightmare - I’ve hit this wall so many times. The workarounds people suggest? They work, but they’re messy as hell.
I jumped ship to Latenode for this exact reason. Arrays actually work like they should. You return your array structure and it processes each object naturally - no weird formatting or extra loop steps needed.
My workflows are so much cleaner now. Code returns the array, email node automatically sends to each address. Done. No data restructuring, no bloated automations.
The debugging tools are miles better too. You can actually see what’s happening with each array item instead of guessing.
Zapier doesn’t automatically loop through arrays from Code steps - it just grabs the first element and ignores the rest. You need to format your return differently so Zapier knows to process each item. Change your return to return {line_items: results}; instead. This tells Zapier each object is a separate line item that you can map in your email step. If that doesn’t work, add a Looping by Zapier step after your Code step - it’ll create separate zap runs for each array element.
had this exact problem last week! wrap your array in an object like return {items: results} then use ‘line item’ mapping in the email step. works way better than the loop workaround.
yeah, zapier has a bit of a quirck with arrays. you should use the loop feature to go through each item, then the email step will work for all users. good luck!
Zapier treats arrays from Code steps as single objects instead of looping through each item. I’ve had to completely restructure my data flow to fix this. Don’t return arrays from your Code step - instead, have it identify what you need, then use a ‘Find Many’ action or API calls to create multiple executions naturally. I’ve also had success using Zapier’s Formatter to split text data, which creates line items automatically. Bottom line: Zapier works better when multiple items come from actions that are built to return multiple results, not from custom code arrays.