Help

Using `UpdateFieldOptionsOpts` when updating field options

Solved
Jump to Solution
2415 4
cancel
Showing results for 
Search instead for 
Did you mean: 
Matthew_Thomas
7 - App Architect
7 - App Architect

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});
}

Screen Shot 2022-08-17 at 3.53.13 PM

1 Solution

Accepted Solutions
Matthew_Thomas
7 - App Architect
7 - App Architect

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!

See Solution in Thread

4 Replies 4

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.

Matthew_Thomas
7 - App Architect
7 - App Architect

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?

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

Matthew_Thomas
7 - App Architect
7 - App Architect

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!