Help

Re: Updating a record field using a script

Solved
Jump to Solution
5915 0
cancel
Showing results for 
Search instead for 
Did you mean: 
ATUser
4 - Data Explorer
4 - Data Explorer

Hi Airtable community,

I’m a complete novice at scripting, so bear with my ignorance here.

I have a table with three fields: Email, Converted Email, and a Button.

I want the button to trigger a script that encodes whatever’s listed in the Email field to base 64 and push it to the Converted Email field.

I’ve gotten this to work so far using this script:

let table = base.getTable("EncodeEmails");
let record = await input.recordAsync("Converting record", table);
let b64 = btoa(record.getCellValueAsString("Email"));
output.inspect(b64);

This outputs the base 64 converted email in the scripting app, which is great. But I want that result to push to the Converted Email field in the record. I’m not quite sure what to do next.

This is what I have so far, pieced together using examples:

let table = base.getTable("EncodeEmails");
let record = await input.recordAsync("Converting record", table);
let b64 = btoa(record.getCellValueAsString("Email"));
let recordId = b64.record[0].id;
await table.updateRecordAsync(recordId, {
    "Converted Email" : b64,
})

But I get this error when I click the button in the record to trigger the script:

TypeError: Cannot read property '0' of undefined
    at main on line 4

I think I’m almost there, I just can’t figure out how to get it to update the record. Greatly appreciate any help!

1 Solution

Accepted Solutions
Kamille_Parks
16 - Uranus
16 - Uranus

Don’t rely on the output of b64 to determine the recordId to update if you already have the record defined. Your recordId should simply be:

let recordId = record.id

See Solution in Thread

2 Replies 2
Kamille_Parks
16 - Uranus
16 - Uranus

Don’t rely on the output of b64 to determine the recordId to update if you already have the record defined. Your recordId should simply be:

let recordId = record.id

that was it! Thank you so much