Help

Typescript updateOptionsAsync() error

Topic Labels: Automations Data
172 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Simon_Malaret
4 - Data Explorer
4 - Data Explorer

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 :

Capture d’écran 2024-11-04 à 12.53.46.png

Errors :

Capture d’écran 2024-11-04 à 12.53.11.pngCapture d’écran 2024-11-04 à 12.50.06.png

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!

1 Reply 1

Hi,
Yes, it's not possible to update options by automation scripting. You can do it only with scripting extension. I'm not sure about Web API, maybe it's also possible. 
I wrote post about similar problem, which I solved by creating another webhook-based automation for that purpose. Automation can still add option to the select field when you use usual 'Update record' step. Thus, I choose random record (indeed, it's query.records[0]), pass record ID, record value of that field (I have only one such field and it's name hardcoded in my script) and array of updates.
Then second automation using repeating group for each array value - it updates record with current repeating group value, then puts old value back. The primary script enters loop, where it checks field options - the list of values. As soon as last array value appear in field options, script exits loop and proceed with further updates.
Well maybe it can be done in a more reasonable way, but for now it's ok for me. 
Here you can find more details