Skip to main content

I have the following piece of code in an automation.

 

 

 

 

 

plantingsWateringsRecordId = await plantingWateringTable.createRecordAsync({

"Watering": [{ id: recordId }],

"Planting": [{ id: planting.id }],

"Crop Picker" : {name: planting.getCellValueAsString("Sort Name & Category")}

})

 

 

 

 

 

The Crop Picker field is a single select field and I want it to expand the selections if the value passed in is not already there. It appears that this can be done using typecast:true but I can't for the life of me figure out where to put it. The documentation is not very clear about this.

Any help would be much appreciated.

Thanks

Ah, `typecast` is available in the Web API, but not in Scripting (which you're using as you're running this in an automation)

In Scripting, you'll need to run updateOptionsAsync like so:

const table = base.getTable("Tasks");

const selectField = table.getField("Priority");

await selectField.updateOptionsAsync({

choices: [...selectField.options.choices, {name: "Urgent"}],

});


https://airtable.com/developers/scripting/api/field#update-options-async


Ah, `typecast` is available in the Web API, but not in Scripting (which you're using as you're running this in an automation)

In Scripting, you'll need to run updateOptionsAsync like so:

const table = base.getTable("Tasks");

const selectField = table.getField("Priority");

await selectField.updateOptionsAsync({

choices: [...selectField.options.choices, {name: "Urgent"}],

});


https://airtable.com/developers/scripting/api/field#update-options-async


Thank you. It makes sense now. One additional question. if the option is already there will it duplicate it?


Thank you. It makes sense now. One additional question. if the option is already there will it duplicate it?


Yeap, that script just creates a new option every time.  If you want to handle duplicates you'll need to pull the current options and check whether the one you want to create already exists I'm afraid


Reply