Hey everyone! I’m having trouble with my Zapier automation. I’ve got two zaps that work fine separately but when I try to combine them into one, things go haywire.
Here’s what I’m trying to do:
- Trigger: Cognito Form (with repeating sections)
- JavaScript: Create arrays from form fields
- Action: Make ZOHO CRM tasks
I’ve tried different ways to combine the zaps:
- Trigger > Code1 > Zoho1 > Code2 > Zoho2 (Zoho2 tasks repeat)
- Trigger > Code1 > Code2 > Zoho1 > Zoho2 (both Zoho tasks repeat)
- Trigger > CombinedCode > Zoho1 > Zoho2 (only Code2 arrays work in Zoho1)
Here’s a simplified version of my code:
function processData(prefix, data) {
if (!data[`string${prefix}Account`]) {
return Array(3).fill([]);
}
return ['Account', 'Notes', 'VisitCall'].map(field =>
data[`string${prefix}${field}`].split(',')
);
}
function createOutput(arrays, prefix) {
return arrays[0].map((_, i) => ({
[`item${prefix}Account`]: arrays[0][i],
[`item${prefix}Notes`]: arrays[1][i],
[`item${prefix}VisitCall`]: arrays[2][i]
}));
}
const vsArrays = processData('VS', inputData);
const ovArrays = processData('OV', inputData);
const vsOutput = createOutput(vsArrays, 'VS');
const ovOutput = createOutput(ovArrays, 'OV');
return [...vsOutput, ...ovOutput];
Any ideas on why it’s looping twice? I’m new to JavaScript, so I might be missing something obvious. Thanks!
I’ve encountered similar issues when working with Zapier automations involving loops and multiple actions. The problem you’re experiencing is likely due to how Zapier handles array outputs in multi-step Zaps.
When you return an array from a Code step, Zapier automatically loops over each item for subsequent steps. This can cause unexpected repetition, especially when combining multiple array outputs.
To resolve this, try wrapping your final output in an object instead of returning a flat array:
return { combinedOutput: [...vsOutput, ...ovOutput] };
Then, in your Zoho CRM actions, you can access the array items using:
{{combinedOutput.[0].itemVSAccount}}
{{combinedOutput.[1].itemOVNotes}}
This approach should prevent unintended looping and allow you to process both VS and OV data in a single Zap without repetition. Let me know if this helps or if you need further clarification!
I’ve faced similar challenges when working with Zapier and JavaScript loops. One thing that helped me was using the .reduce() method instead of .map() for creating outputs. It gives you more control over the iteration process.
Here’s a modified version of your createOutput function that might help:
function createOutput(arrays, prefix) {
return arrays[0].reduce((acc, _, i) => {
if (arrays[0][i] && arrays[1][i] && arrays[2][i]) {
acc.push({
[`item${prefix}Account`]: arrays[0][i],
[`item${prefix}Notes`]: arrays[1][i],
[`item${prefix}VisitCall`]: arrays[2][i]
});
}
return acc;
}, []);
}
This approach ensures that only complete sets of data are included in the output, which might prevent some of the looping issues you’re experiencing. Additionally, consider using Zapier’s built-in ‘Loop’ action if you need to process multiple items separately, as it is designed to handle these scenarios more reliably.
hey john, i had similar probs with zapier loops. try using a single code step and wrap the output in an object like this:
return { allItems: [...vsOutput, ...ovOutput] };
then in zoho actions, use {{allItems.[0].itemVSAccount}} etc. This should stop the weird looping. lmk if it works!