I need help with a Zapier JavaScript code that processes two input dates and generates individual date entries for Airtable record creation. The goal is to take a start date and end date, then produce separate database entries for each day in that range.
According to Zapier documentation, returning an array of objects should trigger the next step multiple times. However, my current implementation only creates a single Airtable record containing all dates instead of individual records for each date.
Here’s what I’ve tried:
var startDate = new Date(inputData.startDay);
var endDate = new Date(inputData.endDay);
var results = [];
var counter = 1;
do {
var currentDay = new String(startDate.toISOString());
results.push(currentDay);
console.log(startDate);
startDate.setDate(startDate.getDate() + 1);
counter++;
}
while (startDate <= endDate);
console.log(results);
return {results};
The next Zapier step recognizes the results variable but treats it as a single value rather than processing each date separately. What’s the correct way to structure this output so Zapier creates multiple Airtable records?
Had this exact issue last month building a booking system. You’re wrapping your array in an object with return {results} - that’s the problem. Return the array directly instead.
Your loop looks fine, but you don’t need new String() since toISOString() already gives you a string. Here’s what fixed it for me:
var startDate = new Date(inputData.startDay);
var endDate = new Date(inputData.endDay);
var results = [];
while (startDate <= endDate) {
results.push({date: startDate.toISOString()});
startDate.setDate(startDate.getDate() + 1);
}
return results;
Just return the array - don’t wrap it. Each element should be an object with the fields you want in Airtable. This created separate records for each date in my workflow.
The issue lies in how you’re structuring the return data. When you return {results}, Zapier interprets that as a single object with a results property that includes the array. To resolve this, change your return statement to:```javascript
return results.map(date => {
return {date: date};
});
zapier needs an array of objects, not just an array. change your return to return results.map(date => ({date: date})); this way each date will be treated like an individual record.