How to create multiple Airtable records from JavaScript array in Zapier automation

I need help with a Zapier workflow where I’m using JavaScript to generate date ranges for Airtable record creation.

I have a script that takes two input dates and should create separate database entries for each date in between. According to Zapier docs, returning an object array should trigger multiple step executions, but I’m only getting one record with all dates combined.

Here’s what I’m working with:

var startDate = new Date(inputData.start);
var endDate = new Date(inputData.end);
var results = [];
var counter = 1;

do {
    var currentDate = new String(startDate.toISOString());
    results.push(currentDate);
    console.log(startDate);
    startDate.setDate(startDate.getDate() + 1);
    counter++;
}
while (startDate <= endDate);

console.log(results);
return {results};

The next step recognizes my results variable but treats it as a single value instead of processing each date separately. What’s the right way to format the return statement so Zapier creates individual Airtable records for each date?

Your return statement’s the problem. Zapier wants each array element as an object, not just a string. Right now you’re returning an object that contains an array, but Zapier expects an array of objects directly.

Try this instead:

var startDate = new Date(inputData.start);
var endDate = new Date(inputData.end);
var results = [];

do {
    results.push({
        date: startDate.toISOString().split('T')[0]
    });
    startDate.setDate(startDate.getDate() + 1);
}
while (startDate <= endDate);

return results;

Two key changes: return the array directly instead of wrapping it, and make each array element an object with named properties. Now Zapier will loop through each object and create separate Airtable records. Each loop gives you access to the date property for mapping to your fields.

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