Trying to create a very basic script

Hello! I am brand new to Airtable scripting and trying to get a very simple script to work with no luck.

What I am trying to accomplish is to have a use click a button then run a script to update 2 fields on that record.

I have pieced this together and it doesn’t show any specific error but also doesn’t change the field (I am starting with only one first to see if I can get this working).

Any ideas on what is going wrong?

// Change these to match your base.
let table = base.getTable('Master_Table');
let field = table.getField('Step');

// When run from a button field, the script skips the prompt
// and automatically uses the button's record.
let record = await input.recordAsync('Choose a record', table);

let value = field.updateOptionsAsync.toString("QC Ready");
1 Like

Welcome to the community, @Lauren_Ober1!

/ When run from a button field, the script skips the prompt
// and automatically uses the button’s record.

That is intended behavior. What were you expecting to happen?

But either way, this snippet you’ve shared doesn’t actually read any data that you could forward to an updateRecordAsync call.

I’m assuming one of the two fields you want to update is called ‘Step’? Is ‘QC Ready’ the other one? What types of fields are those? And where is the data being passed to them supposed to come from?

Finally, the update syntax is wrong, if you click on the Example tab near the bottom of the Scripting app, you should be able to find some verbose examples of how to update a record.

One thing to keep in mind is that the update call is a table method, not a field one, so the invocation should read something like:

const table = base.getTable('Table 1');
const userInput = await input.recordAsync('Select a record to update:',table);
const id = userInput.id;

//always preface create/updateRecord calls with await

await table.updateRecordAsync(

    // id is the same as writing id:id in this instance
    id,
    

    //below is the fields object consisting of key-value pairs that 
    //represent the name of the field you want to update and the new value
    //the format of the value will depend on the type of the field you're trying to update
    {
        "Name":'Test',
        "Notes":'yo','Status':{name:'Done'}}
    );

If you’re still having trouble following, I suggest creating a new table and copy-pasting these few lins of code I’ve shared, they were written with the default field names/values in mind.

1 Like

updateOptionsAsync is for updating the options available in the field configuration. It is not for updating a field value in a cell of a record.

To update the field value for the record, use the syntax provided by Dominic.

You should also use the await keyword with any Airtable functions with async in their name.

1 Like

That worked great! Thank you Kuovonne and Dominic - you guys are the best.

Ƭʜᵃℕҡ ყօϋ

1 Like

This topic was solved and automatically closed 3 days after the last reply. New replies are no longer allowed.