Help

Upcoming database upgrades. Airtable functionality will be reduced for ~15 minutes at 06:00 UTC on Feb. 4 / 10:00 pm PT on Feb. 3. Learn more here

"Find Records" Automation in a Script

Topic Labels: Automations Scripting
202 3
cancel
Showing results for 
Search instead for 
Did you mean: 

Hello everyone,

I am very new to scripting, so hoping I can get some support here.

In short, I am trying to use the "Find Records" automation action to get a list of records, and then pass that list onto the script to delete them. Below is what I have but am getting "TypeError: Invalid arguments passed to table.deleteRecordAsync(recordOrRecordId): • recordOrRecordId → recordOrRecordId should be a Record, not undefined or recordOrRecordId should be a string, not undefined"

I believe this is because the list is being passed to the script as a string, not a record, but am not certain that is the issue or how to rectify. Code is below, thanks in advance!

let table = base.getTable('Milestones');
let inputConfig = input.config();
let recordsToDelete = inputConfig.RecordList;
console.log(recordsToDelete);
for (let deleteRecord of recordsToDelete) {
    await table.deleteRecordAsync(deleteRecord.id);
    output.text(`Deleted record for ${deleteRecord.name}`)
}
3 Replies 3

Can you post screen shots?

- What do you see when you run the script?

- How is the input variable set up?

Other issues:
- How many records are you trying to delete?
- output.text() will not work in an automation.

Hello! 

Because I am terrified of deleting a bunch of records, I am only "testing" the script. This is what I see:ScreenShot.JPG

 

The numbers of record to delete will depend on a couple of things, but at the most it will be ~15. In this test, I am attempting to delete 2.

As mentioned previously, I am very new to this. So almost everything I have done is based on this article, which may be dated (And why output.text() is included): https://www.airscript.dev/2020/05/12/deleting-records

Your "RecordList" is  a list of record IDs, not actual records. You can see this in the "Script Input" section in the top right of your screen capture. Thus, your "recordsToDelete" is an array of record IDs, not records. And your "deleteRecord" is a single record ID, not a full record. So when you tell the computer to get the ".id" of the record ID, it doesn't make sense because you already have an id, and the id does not have an id property.

You can remove the ".id" from like 6 of your code. You should also remove the "output.text" line. I also recommend renaming your variable to reflect the fact that you are working with record IDs and not full records.

Hope this helps! I am typing on a mobile device and I had to choose between replying with bad formatting, or not replying at all.