Help

Auto create Option on automation script

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

I have a webhook that is meant to create new records on a table. Some records have new values for a singleSelect type field. I tried to create a function (code bellow) to provision new options but it fails with “Error: Cannot update field config from scripting automation”.

Without the field my await table.updateRecordAsync also fails if I pass text to this singleSelect field.

Is there any way to provision new values on a option field, to mimic the behavior of the UX where if you paste a new value it is provisioned automatically? if not, a feature request would be the passing of an option to the value of updateRecordAsync such like “create non existing values” or something.

async function updateIfNeeded(table,field,choiceName)
{
    const selectField = table.getField(field);
    if (!selectField.options.choices.find((choice) => choice.name == choiceName))
    {
        await selectField.updateOptionsAsync({
            choices: [
                ...selectField.options.choices,
                {name: choiceName},
            ],
        });
    }


}

Thanks

1 Reply 1

The “Update record” step will create new options without need for a script. Either use your script to output the record ID that needs updating or skip the script entirely if the only the the script is trying to do is modify the single select’s config options.