Skip to main content
Solved

Automation - delete record script not working

  • September 29, 2023
  • 8 replies
  • 68 views

Forum|alt.badge.img+4

I have created a script to delete  a record but it is giving me an error. Here is the code:

 
console.log(`Hello, ${"300 Replens"}!`);
let table = base.getTable("300 Replens")
await table.deleteRecordAsync(input.config()['reckUma1c1NLjQADd']);
 
Here is the log:

CONSOLE.LOG

  1. "Hello, 300 Replens!"

ERROR

TypeError: Invalid arguments passed to table.deleteRecordAsync(recordOrRecordId): • recordOrRecordId → recordOrRecordId should be a Record, not undefined or recordOrRecordId should be a string, not undefined
    at main on line 4

I got the record id after expanding a record and copying it from the google search bar. Why is the log saying undefined?

Thank you

Best answer by ScottWorld

You can see it getting set in the left margin of my screenshot.

Alternatively, if you’re having difficulty with scripting and you just want an easy, no-code way to delete records, you can always use Make’s Airtable Automations, which come with their own “Delete Record” action.

There is a small learning curve with Make, which is why I created this basic navigation video to help. I also provide the links to a few other Make training resources there as well. 

 

 

8 replies

Forum|alt.badge.img+4
  • Author
  • Inspiring
  • September 30, 2023

To add to my post. The log says I can use Record or recordid. How is Record specified? THanks.


dilipborad
Forum|alt.badge.img+23
  • Brainy
  • September 30, 2023

Use variable-based code style like 

 

let inputConfig = input.config(); // Make sure that input.config() should be called only a single time in a script let recordId = inputConfig.recordId // Then use this line with delete function await table.deleteRecordAsync(recordId);

 

See the attached image as well.

I hope this helps.


ScottWorld
Forum|alt.badge.img+35
  • Genius
  • September 30, 2023

That script will not work. The script below is a working deletion script, if you define myRecord as shown in the screenshot below:

 

let inputConfig = input.config();
let recordId = inputConfig.myRecord;
let table = base.getTable("Type Your Table Name Here");
await table.deleteRecordAsync(recordId);

 


Forum|alt.badge.img+4
  • Author
  • Inspiring
  • September 30, 2023

That script will not work. The script below is a working deletion script, if you define myRecord as shown in the screenshot below:

 

let inputConfig = input.config();
let recordId = inputConfig.myRecord;
let table = base.getTable("Type Your Table Name Here");
await table.deleteRecordAsync(recordId);

 


Hi ScottWorld, thank you for your response but I'm still getting the same errors see log below. Is recordid specified outside of the script maybe?

ERROR
TypeError: Invalid arguments passed to table.deleteRecordAsync(recordOrRecordId):
• recordOrRecordId →
recordOrRecordId should be a Record, not undefined
or recordOrRecordId should be a string, not undefined

at main on line 4

thanks


Forum|alt.badge.img+4
  • Author
  • Inspiring
  • September 30, 2023

Use variable-based code style like 

 

let inputConfig = input.config(); // Make sure that input.config() should be called only a single time in a script let recordId = inputConfig.recordId // Then use this line with delete function await table.deleteRecordAsync(recordId);

 

See the attached image as well.

I hope this helps.


Where does recordid get specified? Thanks.


ScottWorld
Forum|alt.badge.img+35
  • Genius
  • Answer
  • September 30, 2023

You can see it getting set in the left margin of my screenshot.

Alternatively, if you’re having difficulty with scripting and you just want an easy, no-code way to delete records, you can always use Make’s Airtable Automations, which come with their own “Delete Record” action.

There is a small learning curve with Make, which is why I created this basic navigation video to help. I also provide the links to a few other Make training resources there as well. 

 

 


Forum|alt.badge.img+4
  • Author
  • Inspiring
  • September 30, 2023

Hi ScottWorld, Thanks for the quick response. It's working now and thanks for the links.


Alexey_Gusev
Forum|alt.badge.img+25

Hi ScottWorld, Thanks for the quick response. It's working now and thanks for the links.


You can use input.config() directly, if you have just one input variable

let recordId = input.config().myRecord;

and even use 'oneliner'

await base.getTable('table_name').deleteRecordAsync(input.config().recordId)

 but if you want to understand at least code basics, I would recommend to move step by step ))