I need help with a Zapier JavaScript function that generates dates between two given dates. 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 per date.
Here’s what I’ve tried:
var startDate = new Date(inputData.startDate);
var endDate = new Date(inputData.endDate);
var results = [];
var counter = 1;
while (startDate <= endDate) {
var currentDate = startDate.toISOString();
results.push(currentDate);
console.log(startDate);
startDate.setDate(startDate.getDate() + 1);
counter++;
}
console.log(results);
return {results};
The issue is that Zapier treats this as a single output value rather than multiple separate values. What’s the correct way to structure the return statement so each date creates its own Airtable record?
yup, u nailed it! it’s def about that object wrapper. zapier needs the plain array, not an object around it. and don’t forget to structure each array item as an object that aligns with your airtable fields; just pushing strings won’t give u individual records.
This is simpler than you think. Your code structure looks fine, but you’re returning an object when Zapier wants a plain array.
Change this:
return {results};
To this:
return results;
There’s another issue though - you’re pushing strings when Zapier needs objects. Each array element should match your Airtable field structure.
Here’s the fix:
var startDate = new Date(inputData.startDate);
var endDate = new Date(inputData.endDate);
var results = [];
while (startDate <= endDate) {
results.push({
dateField: startDate.toISOString().split('T')[0]
});
startDate.setDate(startDate.getDate() + 1);
}
return results;
Just replace dateField with your actual Airtable column name. Each object becomes one Airtable record.
I’ve hit this exact problem before with bulk data imports. Zapier’s pretty strict about return formats for triggering multiple actions.
You’re wrapping your array in an object with return {results} - that’s the issue. Zapier needs a flat array of objects to create multiple records, not an array buried inside an object property. Try this instead: javascript var startDate = new Date(inputData.startDate); var endDate = new Date(inputData.endDate); var results = []; while (startDate <= endDate) { results.push({ date: startDate.toISOString().split('T')[0], timestamp: startDate.toISOString() }); startDate.setDate(startDate.getDate() + 1); } return results; Return the array directly and structure each element as an object with your Airtable fields. Each object in the returned array triggers a separate execution of your next step, creating individual records like you want.