I need help with a Zapier JavaScript function that takes two input dates and generates all the dates between them. The goal is to create separate Airtable records for each date in the range.
According to Zapier documentation, returning an array of objects should trigger the next step multiple times. However, my current implementation only creates one record containing all dates instead of individual records for each date.
Here’s what I’ve tried so far:
var startDate = new Date(inputData.startDate);
var endDate = new Date(inputData.endDate);
var dateArray = [];
var counter = 0;
while (startDate <= endDate) {
var currentDate = startDate.toISOString().split('T')[0];
dateArray.push(currentDate);
startDate.setDate(startDate.getDate() + 1);
counter++;
}
console.log('Generated dates:', dateArray);
return { dateArray };
The issue is that Zapier treats my output as a single value rather than processing each date separately. What’s the correct way to structure the return statement so that each date creates its own Airtable record?
You’re mutating the same Date object reference when you modify startDate directly with setDate(). That’s what’s causing the weird behavior. Here’s a better approach:
var startDate = new Date(inputData.startDate);
var endDate = new Date(inputData.endDate);
var results = [];
for (var current = new Date(startDate); current <= endDate; current.setDate(current.getDate() + 1)) {
results.push({
date: current.toISOString().split('T')[0]
});
}
return results;
I’ve hit this same issue building automated reports. The main difference is returning an array of objects directly instead of nesting it. Each object becomes a separate trigger for your Airtable step.
Make sure your Airtable action handles the date field correctly. JavaScript and Airtable sometimes clash on timezone handling, causing off-by-one errors. Test with a small date range first.
Zapier’s choking on your output structure. When you return { dateArray }, it sees one object with one property - not multiple items to loop through.
I hit this exact issue building an event scheduler. Fix is simple - return an array where each element is its own object:
var startDate = new Date(inputData.startDate);
var endDate = new Date(inputData.endDate);
var output = [];
while (startDate <= endDate) {
output.push({
targetDate: startDate.toISOString().split('T')[0]
});
startDate = new Date(startDate.getTime() + 24 * 60 * 60 * 1000);
}
return output;
I’m creating a fresh Date object each loop instead of changing the original. This avoids the weird date calculation bugs you get with setDate(). Each object in your array will trigger the Airtable action once, so you’ll get separate records like you want.
You’re wrapping your array in an object - that’s the issue. Zapier needs a flat array of objects to trigger multiple executions.
Change your return to this:
var startDate = new Date(inputData.startDate);
var endDate = new Date(inputData.endDate);
var dateArray = [];
while (startDate <= endDate) {
var currentDate = startDate.toISOString().split('T')[0];
dateArray.push({ date: currentDate });
startDate.setDate(startDate.getDate() + 1);
}
return dateArray;
Two key changes: wrap each date in an object with a property name, and return the array directly instead of { dateArray }.
I hit this exact problem last year building a scheduling system. Zapier’s docs aren’t clear about it, but array elements must be objects, not primitive values.
Need multiple fields per record? Expand the object:
dateArray.push({
date: currentDate,
status: 'pending',
created_at: new Date().toISOString()
});
This works great for bulk operations. I’ve created hundreds of records at once without hitting API limits.