Using `UpdateFieldOptionsOpts` when updating field options

I’m trying to overwrite a Field’s options with a list provided dynamically from data that is imported. I have successfully updated the options to use the previous values in addition to the new set of values (similar to the example the documentation provides).

However, the use case for my app is to start from scratch: delete all existing records (and ideally field options), and import a fresh set of data with field options that match the new data. The documentation points to UpdateFieldOptionsOpts as a way to do this, but after trying a few combinations, I have not gotten it to work.

Any thoughts from the community on what I might be doing wrong? Here is some sample code to demonstrate the issue:

let choices = {
    choices: [
        {"name": "Option 1"},
        {"name": "Option 2"},
    ]
}

if (field.hasPermissionToUpdateOptions(choices)) {
    await field.updateOptionsAsync(choices, {"enableSelectFieldChoiceDeletion": true});
}

I’ve not tried that behavior myself (and don’t have time to develop a test), but on the surface everything looks good. The only minor thing that sticks out is that you’re using strings as object keys instead of just typing the name with no surrounding quotes. This shouldn’t make a difference, and I’m only mentioning it because it feels out of the ordinary, but it might be worth removing the quotes. I’ve seen pretty simple things lead to errors, so it couldn’t hurt to try.

As an alternative approach to solving this problem, what about using a linked record field instead of a select field? Clear and recreate the contents of the target table as needed when new data is loaded. It’s not quite as simple as dealing with a single-/multi-select field, but I can’t think of any hiccups that would arise from that process.

Hi Justin, thanks for the suggestions!

Unfortunately, the problem occurs both with and without quotes around the object keys. It will also fail when there is the check for hasPermissionToUpdateOptions() and if I just call updateOptionsAsync() directly.

Your alternate approach to using linked records is interesting, but I think adds too much overhead to the use case I have. While less elegant, I think just adding the new options to the existing options would be better suited.

This does sound like a bug in the API to me. Do you know if the recommendation for filing a report is still through the Help? > Message Support within a base?

1 Like

That works. You can also email support@airtable.com.

1 Like

Looking into this problem more, it turns out the issue was the package version I was using. The enableSelectFieldChoiceDeletion option was added in v1.8.0 and my code was still using v1.5.1. Updating the package fixed the issue and the code is working as expected!

3 Likes

This topic was solved and automatically closed 3 days after the last reply. New replies are no longer allowed.