How to generate array of date objects in Zapier JavaScript for creating multiple Airtable records

I need help with a Zapier JavaScript code that processes date ranges. My goal is to take a start date and end date, then generate all the dates in between. Each date should create a separate record in my Airtable database.

According to Zapier documentation, returning an array of objects should trigger the next step multiple times. However, my current implementation only creates one database record containing all dates instead of individual records.

Here’s what I’ve tried so far:

var startDate = new Date(inputData.startValue);
var endDate = new Date(inputData.endValue);
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 Zapier step recognizes my results variable but treats it as a single value rather than separate items. What am I doing wrong with the array structure?

yeah, jackhero’s right - wrapping it in an object is the issue. also drop new String() and just use startDate.toISOString() directly. zapier wants a plain array, not an object containing an array. just return results; and you’re good.

Your return statement structure is the issue. With Zapier’s multi-step triggers, the array format really matters. Don’t return an object with a results property - return the array directly. You’ve got another problem too: you’re modifying the original startDate object in your loop, which causes weird behavior. Create a new Date object for each iteration instead. Your loop logic works, but try while instead of do-while to handle cases where the start date’s already past the end date. Bottom line: Zapier wants a flat array for multiple records, not nested objects.

Your issue stems from return {results} as it encapsulates your array within an object. To enable Zapier to trigger multiple executions for each date, simply update it to return results. Additionally, ensure you’re using new Date(startDate) to avoid reference problems with the date objects. I’ve encountered a similar challenge in the past, and making these adjustments resolved my multiple record creation issue.

Your main issue is how you’re returning results. Zapier needs arrays for multiple iterations, so return the results array directly - don’t wrap it in an object. That’s what’s stopping Zapier from creating separate records for each date. Also, ditch the do-while loop. A regular while loop gives you better control and won’t run extra iterations. Make sure each date is structured as an object that matches your Airtable fields, or Zapier will consolidate everything into one record.

I hit this exact issue last year building a project tracker. It’s the object wrapper causing problems, but there’s a cleaner way to handle the date loop.

Try this:

var startDate = new Date(inputData.startValue);
var endDate = new Date(inputData.endValue);
var results = [];

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

return results;

Two changes: return the array directly and make each item an object with your date field. Zapier needs each array element as an object representing one record, not raw values.

Learned this the hard way - Zapier won’t process plain values properly. The split on ‘T’ strips out the time if you only need the date.