Skip to main content

Automations: Deleting a record


I was wondering if it was possible to setup an automation that would auto delete a record with a specific single-select field entry after 30 days or something.

10 replies

JonathanBowen
Forum|alt.badge.img+18

Hi @Jeffrey_Yau - Airtable automations don’t currently have a delete action, but you can do the following:

When a record enters a view => Run a script

The view would be defined as:

  • Single select field = ‘XXXX’ and
  • Last modified date > 30 days ago

The script would take the record from the trigger and delete it - see here for more details:


Forum|alt.badge.img+12
  • Participating Frequently
  • 93 replies
  • July 29, 2021

Hi :wave: , this is an old post, but I will leave this solution for other people looking for it.

You can use this code inside the automations in a “Run script” step:

let inputConfig = input.config();
const id = inputConfig.id;
const Table = base.getTable(inputConfig.Table);
await Table.deleteRecordAsync(id);

You then configure “Table” & “id” as input variables, “Table” is the name of the table of the record, and “id” is the Record ID that regularly will come from a previous step.

This step will delete the record with that record id.


Forum|alt.badge.img
SergioCodes wrote:

Hi :wave: , this is an old post, but I will leave this solution for other people looking for it.

You can use this code inside the automations in a “Run script” step:

let inputConfig = input.config();
const id = inputConfig.id;
const Table = base.getTable(inputConfig.Table);
await Table.deleteRecordAsync(id);

You then configure “Table” & “id” as input variables, “Table” is the name of the table of the record, and “id” is the Record ID that regularly will come from a previous step.

This step will delete the record with that record id.


You then configure “Table” & “id” as input variables

Hello @SergioCodes , I am trying to use the code you posted above but with little luck. I don’t know how to set up the variables and I get

TypeError: Invalid arguments passed to base.getTable(idOrName): • idOrName should be a string, not undefined

could you elaborate a little?


Forum|alt.badge.img+12
  • Participating Frequently
  • 93 replies
  • June 16, 2022
Matteo_Mandrile wrote:

You then configure “Table” & “id” as input variables

Hello @SergioCodes , I am trying to use the code you posted above but with little luck. I don’t know how to set up the variables and I get

TypeError: Invalid arguments passed to base.getTable(idOrName): • idOrName should be a string, not undefined

could you elaborate a little?


Hi,

Happy to help, just change this line:

const Table = base.getTable(inputConfig.Table);

for

const Table = base.getTable("TableName");

Where “TableName” is the name of your table and it should work


Forum|alt.badge.img
SergioCodes wrote:

Hi,

Happy to help, just change this line:

const Table = base.getTable(inputConfig.Table);

for

const Table = base.getTable("TableName");

Where “TableName” is the name of your table and it should work


@SergioCodes Thank you!


Forum|alt.badge.img+5
  • Inspiring
  • 16 replies
  • June 21, 2022
SergioCodes wrote:

Hi,

Happy to help, just change this line:

const Table = base.getTable(inputConfig.Table);

for

const Table = base.getTable("TableName");

Where “TableName” is the name of your table and it should work


Hey, I am not sure what I am doing incorrect. I have no idea how scripts work.

Can you please help me?


kuovonne
Forum|alt.badge.img+27
  • Brainy
  • 6002 replies
  • June 21, 2022
Pratik_Shah wrote:

Hey, I am not sure what I am doing incorrect. I have no idea how scripts work.

Can you please help me?


You cut off the right side of the screen in your screen shot. What does it say?

Are you getting an error when you run the script? Have you tried retesting the trigger to get a new record ID? If you have already deleted the record, you cannot delete it again.

What is the value of your id? The script won’t work unless it is exactly one Airtable record ID. E.g. it won’t work if there are no IDs in the input variable, and it won’t work if there are multiple record IDs, and it won’t work if the IDs are not Airtable record IDs.

By the way as a matter of styling, it is customary to start variable names with a lower case letter, so Table would be table. However, this is not what is causing your issues.


Forum|alt.badge.img+5
  • Inspiring
  • 16 replies
  • June 21, 2022
kuovonne wrote:

You cut off the right side of the screen in your screen shot. What does it say?

Are you getting an error when you run the script? Have you tried retesting the trigger to get a new record ID? If you have already deleted the record, you cannot delete it again.

What is the value of your id? The script won’t work unless it is exactly one Airtable record ID. E.g. it won’t work if there are no IDs in the input variable, and it won’t work if there are multiple record IDs, and it won’t work if the IDs are not Airtable record IDs.

By the way as a matter of styling, it is customary to start variable names with a lower case letter, so Table would be table. However, this is not what is causing your issues.


Thank you for the response.

My previous step is “Find Record” which will always fine one record alongwith its record id.

It is actually one record id only but I assume, since find record module gets array of the records (whether one record or more than one), it may not be working. I tried putting actual record id, it was working properly.

Any specific solution?


kuovonne
Forum|alt.badge.img+27
  • Brainy
  • 6002 replies
  • June 21, 2022
Pratik_Shah wrote:

Thank you for the response.

My previous step is “Find Record” which will always fine one record alongwith its record id.

It is actually one record id only but I assume, since find record module gets array of the records (whether one record or more than one), it may not be working. I tried putting actual record id, it was working properly.

Any specific solution?


No specific solutions. But try console.log(id) to see what the actual value is. Then also search your table for a record with that id. Those two bits of information should help troubleshoot.


Forum|alt.badge.img+5
  • Inspiring
  • 16 replies
  • June 28, 2022
kuovonne wrote:

No specific solutions. But try console.log(id) to see what the actual value is. Then also search your table for a record with that id. Those two bits of information should help troubleshoot.


Thank you so much for your help


Reply