I’m working on a Zapier automation to populate an Airtable database with multiple dated records. My goal is to create a JavaScript function that takes two dates as input and returns all the dates in between.
I’ve written some code that generates the dates, but it’s not working as expected. When I try to create the database records, only one record is made with all the dates combined. Here’s what I’ve got so far:
function getDates(start, end) {
let current = new Date(start);
const stopDate = new Date(end);
const dateList = [];
while (current <= stopDate) {
dateList.push(current.toISOString().split('T')[0]);
current.setDate(current.getDate() + 1);
}
return { dates: dateList };
}
The next step in Zapier sees the output, but it’s treating it as a single value instead of separate dates. Any ideas on how to fix this so I can create individual records for each date in Airtable? Thanks for any help!
Your JavaScript function looks correct for generating the array of dates. The issue likely lies with how Zapier is handling the output. To create individual records in Airtable, you’ll need to use Zapier’s ‘Create Multiple’ action instead of a regular ‘Create’ action.
In your Zap, after the step with your code, add a ‘Create Multiple’ Airtable action. Then, in the mapping for this action, you can use the ‘dates’ output from your code step as the source for creating multiple records. Zapier should then iterate over each date in the array and create a separate record for each.
If you’re still having trouble, you might need to adjust your code to output a format Zapier expects for multiple records, typically an array of objects. Something like:
return dateList.map(date => ({ Date: date }));
This should give Zapier the structure it needs to create multiple records in Airtable.
Hey neo_stars, i’ve run into this before. The problem’s probably with zapier, not ur code. Try using the ‘create multiple’ action in zapier instead of the regular ‘create’ one. It should handle ur array of dates better and make separate records for each date in airtable. Lemme know if that works!
I’ve dealt with similar issues when automating date-based records in Airtable through Zapier. Your approach is on the right track, but there’s a small tweak that might solve your problem. Instead of returning an object with a ‘dates’ property, try returning the array directly:
return dateList;
This should give Zapier a straightforward array to work with. Then, in your Zap, use the ‘Create Multiple’ action for Airtable as others have suggested. Map the output of your code step directly to the date field in Airtable.
If you’re still having trouble, you might need to adjust your Zap’s settings to ensure it’s treating each array element as a separate item. Look for options like ‘Split into multiple items’ or similar in your Zap configuration.
Remember, Zapier can be finicky with data structures, so sometimes it’s about finding the right format that both your code and Zapier can agree on. Good luck with your automation!