Help

The Community will be temporarily unavailable starting on Friday February 28. We’ll be back as soon as we can! To learn more, check out our Announcements blog post.

Record not updating on Error

Solved
Jump to Solution
1570 4
cancel
Showing results for 
Search instead for 
Did you mean: 
OfficeOurs
7 - App Architect
7 - App Architect

Hi,

I'd like to insert the error message into a field, so I used try catch with both of them updating a variable, which I then used to update the field. Weird; it only updated on success, not on error. Can anyone help?

 

let config = input.config();
const recordId = config.recordid;
let tabletable = config.tabletable;
let table = base.getTable(tabletable);
let query = await table.selectRecordsAsync({ fields: ["Error"] });
let err;
try {
    await table.updateRecordAsync(recordId, {
        "Eat": "Cheese" // no such field
    })
    err = "Code executed successfully";
} catch (error) {
    err =  error.message;
    } finally {
    console.log(err);
    await table.updateRecordAsync(recordId, {
        "Error": err
    }
    );
    }


console.log("Updated a record!");

 

 

CONSOLE.LOG
"Could not find a field with name or ID "Eat"."
ERROR
Error: Could not find a field with name or ID "Eat".
    at main on line 16

As you can see, err was properly logged. But the record was not updated.

 

1 Solution

Accepted Solutions

I ended up outputting the Error and then using the update field action to update the field.

See Solution in Thread

4 Replies 4
Devinder_Singh
6 - Interface Innovator
6 - Interface Innovator

table.updateRecordAsync returns a Promise, and its error handling is different. The failure will not go to the catch block as you've written.

You should use catch as how it's used in this reply: https://community.airtable.com/t5/development-apis/error-handling-if-single-select-field-option-does...

But it caught the err, and pushed it out to console.log. It just didn't update the error field in the table.

Did you ever figure out how to update a record within the catch block? I'm running into the same issue.

I ended up outputting the Error and then using the update field action to update the field.