Skip to main content
Solved

Updating a record field using a script

  • June 9, 2021
  • 2 replies
  • 338 views

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!

Best answer by Kamille_Parks11

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

2 replies

Kamille_Parks11
Forum|alt.badge.img+27
  • Brainy
  • 2679 replies
  • Answer
  • June 9, 2021

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

  • Author
  • New Participant
  • 1 reply
  • June 9, 2021

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