Jul 23, 2024 05:10 PM
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
Jul 23, 2024 05:52 PM
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
Jul 23, 2024 06:31 PM
Thank you. It makes sense now. One additional question. if the option is already there will it duplicate it?
Jul 23, 2024 07:12 PM
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