Help

Re: How to mark a record for deletion automatically after 18 hours?

2929 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Steve_Marks1
5 - Automation Enthusiast
5 - Automation Enthusiast

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!

9 Replies 9

You can do this with Airtable automations and a Scripting Action, although it might not run at exactly 18 hours.

formula field

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")

automation trigger

Use the When record matches conditions trigger, and set the trigger for when the formula field is not empty.

scripting action input variables

Setup two input variables:

  • recordId for the recordId from the triggering record
  • tableName for the table name (simply type the name)

scripting action code

let inputConfig = input.config();
const recordId = inputConfig.recordId;
const table = base.getTable(inputConfig.tableName)
await table.deleteRecordAsync(recordId)

Notes on this method

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?

Screen Shot 2020-09-14 at 7.07.09 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.

Denji_Mo
5 - Automation Enthusiast
5 - Automation Enthusiast

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?
aritableerror

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.

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.

@Steve_Marks1 We have a meeting scheduled for tomorrow (rescheduled from last week). Will that still work for you?

Yes, it will. Looking forward to it!

Denji_Mo
5 - Automation Enthusiast
5 - Automation Enthusiast

You were right. Thank you.^^