Hi all,
I am trying to update a select field options, as mentioned in the documentation.
It would seem that I can not update the options of a selectField within my automation 'Run a script' module.
Documentation :
Errors :
Code:
// Create new entries if necessary
const uniqueUpdateOptions = sortedRecords.map(record => record.fields['Price Wave Number'].name);
const newOptions = getNewOptions(uniqueUpdateOptions);
const selectField = priceWavesTable.getField('Price Wave Number');
await selectField.updateOptionsAsync({ choices: newOptions }) // typescript is not sure this will be of type singleSelect
function getNewOptions(updateOptions) {
// Get the existing options for the "Price Wave Number" field
const selectField = priceWavesTable.fields
.filter(field => field.name === "Price Wave Number" && field.type === "singleSelect")[0];
if (!selectField) return;
const selectFieldOptions = selectField.options?.choices || [];
if (!selectFieldOptions) return;
// Identify options that need to be added
const optionsToAdd = updateOptions.filter(updateOption =>
!selectFieldOptions.some(fieldOption => fieldOption.name === updateOption)
) || [];
// If there are options to add, proceed with the update
if (optionsToAdd.length > 0) {
const newOptions = [
...selectFieldOptions, // Include existing options
...optionsToAdd.map(optionName => ({ name: optionName })) // Add new options
];
return newOptions;
}
return [];
}
Would you have any thoughts as to why this is ?
Is this just a feature that we can not update options in scripting so the doc needs update?
Thank you!