Re: Is there an ID for MultiSelect options and Single Select?

297 1
Showing results for 
Search instead for 
Did you mean: 
8 - Airtable Astronomer
8 - Airtable Astronomer

I am trying to develop a script with a mutli-select option. Is there a code for each of these so if I choose to change the actual name, it won’t be a problem?

8 Replies 8

Hi @Rose_Haft1 - Single and Multi-select fields have a similar structure. A single select is an object of id, name and colour. Multi-select is an array of these objects:

Screenshot 2020-12-21 at 18.11.40

You can reference the select value or values by the id rather than the name and if the name is changed the id will remain the same. When creating or updating a single select field you can write to is using the id or the name:

Screenshot 2020-12-21 at 18.14.43

So, as you want to do, if you go for the id option here you will be fine.

Thanks. That is great. Do you have a sample of how I would reference these with script? I have not been able to figure this out…

@Rose_Haft1 - if I have two single select fields like this:

Screenshot 2020-12-22 at 21.35.07

Then this script will get the values of each value in the first field, then updates the second field with its value:

let table = base.getTable('Table 1');
let query = await table.selectRecordsAsync();

// read the values
for (let record of query.records) {
    let id = record.getCellValue('Single Select').id;
    let name = record.getCellValue('Single Select').name;
    let color = record.getCellValue('Single Select').color;

    // read/log the values
    console.log(id, name, color)

    // write the values
    table.updateRecordAsync(record, {
        'Single Select 2': {id: id}
        // or:
        // 'Single Select 2': {name: name}

It is similar for a multi-select, but you would have to iterate over each value within the field:

record.getCellValue('Multi Select')

Is there a way to reference the list of potential single-select values? If so, this could be used to simulate a dropdown single-select using the button input.

You can get the values from the field options.

You don’t actually need the select ids. I usually map the single select choice names to the choices for an input button.

Thank you for calling this out!

I usually map the single select choice names to the choices for an input button.

Do you have an example? :slightly_smiling_face:

Edit: Figured it out. Hopefully this helps someone else:

let exampleTable = base.getTable("table");
let fieldName = 'example dropdown'
let buttonVal = await input.buttonsAsync(`Example button label`, exampleTable.getField(fieldName).options['choices'].map(choice => {
    return {
        'label': Object.values(choice)[1]

Thank you. Are these all the properties that can be accessed?

Yes. They are all that are listed in the documentation. Note that the color might not exist if the options are not in color. You can also determine the order of the options from the order of the choices in the array.

Were you hoping for additional properties? If so, which ones?