Help

How to use the typecast parameter in an automation using createRecordAsync

Topic Labels: Automations
573 3
cancel
Showing results for 
Search instead for 
Did you mean: 
Lee_Mandell
6 - Interface Innovator
6 - Interface Innovator

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

3 Replies 3

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?

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