Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Sep 29, 2023 04:55 PM
I have created a script to delete a record but it is giving me an error. Here is the code:
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
Solved! Go to Solution.
Sep 30, 2023 11:22 AM - edited Sep 30, 2023 11:22 AM
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.
Sep 29, 2023 05:08 PM
To add to my post. The log says I can use Record or recordid. How is Record specified? THanks.
Sep 29, 2023 10:24 PM - edited Sep 29, 2023 10:26 PM
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.
Sep 30, 2023 04:51 AM - edited Sep 30, 2023 04:53 AM
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);
Sep 30, 2023 08:45 AM
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
Sep 30, 2023 08:49 AM
Where does recordid get specified? Thanks.
Sep 30, 2023 11:22 AM - edited Sep 30, 2023 11:22 AM
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.
Sep 30, 2023 01:00 PM
Hi ScottWorld, Thanks for the quick response. It's working now and thanks for the links.
Oct 01, 2023 11:36 AM
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 ))