Hi All! I’m currently importing records in the morning, and would like to set up an automation to mark each one for deletion 18 hours later. Two questions:
Is it possible to delete the records automatically (using automations), just inside of Airtable?
If no, I can use Integromat to do the deletion. However, how would I mark each record for deletion once it’s entered into the base?
Thanks in advance for helping out this Airtable noob!
You can do this with Airtable automations and a Scripting Action, although it might not run at exactly 18 hours.
Create a new formula field that calculates if the record was created over 18 hours ago.
IF(DATETIME_DIFF(NOW(), CREATED_TIME(), 'hours') > 18, "delete")
Use the When record matches conditions trigger, and set the trigger for when the formula field is not empty.
Setup two input variables:
let inputConfig = input.config(); const recordId = inputConfig.recordId; const table = base.getTable(inputConfig.tableName) await table.deleteRecordAsync(recordId)
This method relies on Airtable recalculating the formula field behind the scenes. Officially, the documentation states that the results of the
NOW() function is not updated continuously. However, multiple users have used automations with
NOW updating behind the scenes, although the actual execution time might be several minutes after the target time.
Airtable’s When record matches conditions trigger is relatively new, and it seems to behave like the When record enters view trigger, without having to actually create a view. Thus, if a record already meets the conditions before the automation is turned on, it will not trigger the automation, just as the record would not “enter” the view because it would already be “in” the view. The only exception is the record retrieved when testing the automation.
Thank you so much @kuovonne. I am so close, thanks to your advice.
I think the “recordId” piece is holding me up. (Please forgive me - I am new to scripting.) What should I put into “Value” for the recordId input variable so that this works?
Thank you for the screen shot. To get the record Id as an input variable you need to click the blue + sign where you define that input variable and follow the prompts to select the triggering record and get its record id.
Were you able to successfully test the first part of the automation–getting a record based on the trigger? If so, did you test this second part of the automation (running the script) more than once? The first time you test the script, it would delete the record found in the first step, and thus the script won’t work a second time on the same record because it has already been deleted. You cannot delete the same record twice.