Skip to main content

How to use the typecast parameter in an automation using createRecordAsync

  • July 24, 2024
  • 3 replies
  • 322 views

Forum|alt.badge.img+7

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

TheTimeSavingCo
Forum|alt.badge.img+31

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


Forum|alt.badge.img+7
  • Author
  • Known Participant
  • 16 replies
  • July 24, 2024

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?


TheTimeSavingCo
Forum|alt.badge.img+31

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