Updating record from script button

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?

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

2 Likes