Sep 13, 2020 02:59 PM
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!
Sep 13, 2020 10:30 PM
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.
Sep 14, 2020 04:21 PM
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?
Sep 14, 2020 04:30 PM
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.
Sep 21, 2020 04:25 AM
I am happy to see the article I was looking for. By the way, I pressed the blue + mark and put the recordID correctly, and “TEST” was disabled. I don’t know what’s wrong. Can you help me?
Sep 21, 2020 05:27 PM
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.
Sep 22, 2020 12:45 PM
I was able to mark all records with the word “delete” once in there for 12 hours. (I changed this from 18 hours). The part I’m struggling with is the script and the “record ID” part. Would love to show you over a screenshare and see what you think.
Sep 22, 2020 01:10 PM
@Steve_Marks1 We have a meeting scheduled for tomorrow (rescheduled from last week). Will that still work for you?
Sep 22, 2020 01:36 PM
Yes, it will. Looking forward to it!
Sep 25, 2020 04:07 AM
You were right. Thank you.^^