Help

Automation - delete record script not working

Topic Labels: Automations
Solved
Jump to Solution
1604 8
cancel
Showing results for 
Search instead for 
Did you mean: 
Alexi_Mosnov
6 - Interface Innovator
6 - Interface Innovator

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
1 Solution

Accepted Solutions
ScottWorld
18 - Pluto
18 - Pluto

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. 

 

 

See Solution in Thread

8 Replies 8
Alexi_Mosnov
6 - Interface Innovator
6 - Interface Innovator

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

dilipborad
9 - Sun
9 - Sun

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
18 - Pluto
18 - Pluto

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

 IMG_0240.jpeg

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

Where does recordid get specified? Thanks.

ScottWorld
18 - Pluto
18 - Pluto

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. 

 

 

Alexi_Mosnov
6 - Interface Innovator
6 - Interface Innovator

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