Help

The Community will be temporarily unavailable starting on Friday February 28. We’ll be back as soon as we can! To learn more, check out our Announcements blog post.

Delete Records with dates that is 60 days prior from today using the Script

Topic Labels: Automations
1032 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Deepthy_Mathew
4 - Data Explorer
4 - Data Explorer

Hi All,

I am new to the airtable and Airtable Automations.

I have a table with a column ‘Filled Date’. I wanted to schedule an automation to happen every night to delete the records with a date that is 60 days prior to today.

I don’t know if am doing it wrong, but I tried to filter the rows using below code, but it’s filtering entire records:

var today = new Date();
const table = base.getTable(“Table1”);
const query = await table.selectRecordsAsync({
fields: [“Filled Date”]
});
const todelete = query.records.filter(rec => Math.ceil(Math.abs(today.getTime() - new Date(rec.getCellValue(“Filled Date”)).getTime()/ (1000 * 60 * 60 * 24))) > 60);
console.log(todelete);

Can anyone help me on this. Any advise is much appreciated. Thank you.

1 Reply 1

Welcome to the Airtable community!

Notice that your order of operations is off. You are converting only the record date/time to days, not the difference in time. Thus, you are probably getting all the records in the table.

Try adding a set of parentheses to fix the order of operations.

It might be easier for you to have a filtered view to do the date calculations and then have the automation script simply delete all the records in the view.