Help

Updating record from script button

Topic Labels: Scripting extentions
2334 1
cancel
Showing results for 
Search instead for 
Did you mean: 
pier24
4 - Data Explorer
4 - Data Explorer

Good morning, i have a problem with my script.
I want to update a record from a script button and i write this code:

// Delete a record
let table = base.getTable("Clients");
let record = input.recordAsync;                      
table.updateRecordAsync(record, {'Name': 'Update'});

This doesn’t work and i don’t understand why. The only message i get is
This script did not use the record from the button field. To use a record from a button field, call input.recordAsync in your script
Anyone can help me please?

1 Reply 1

Hi @pier24 - you need to use this pattern for input.recordAsync:

let table = base.getTable("Tasks");
let record = await input.recordAsync('Pick a record', table);
if (record) {
    output.text(`You picked ${record.getCellValueAsString("Description")}`);
}

So, modifying your script a little, this would be something like:

let table = base.getTable('Clients');
let record = await input.recordAsync('Pick a record', table);
if (record) {
    await table.updateRecordAsync(record, {'Name': 'Updated'})
}

Although it looks like it is prompting you to select a record, if you attach this script to a button on a record, then this happens automatically in the background