Remove choices except a few choices
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2024 11:33 PM
Hi All,
I want to remove all the existing choices from a choice field without removing a few choices(suppose 5) .
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 12:32 AM
Hello Dipika,'
Instead of doing this on the client side, if you don't want these choices, why have it in first place? Remove it from dictionary altogether.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 12:46 AM
So are you saying to inactive the choices manually from dictionary in DEV,QA,UAT and PROD ?
If yes , will it be the best practice to do ? I am not sure, please clarify .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 12:50 AM
depends, do you want these choices or no? If yes, best practise will be to remove the options so it shows the right options only. If there is a use case to remove options temporarily which will be used on some other conditions, you can use the below script -
function onLoad() {
var fieldName = 'your_field_name'; // Replace with your actual choice field name
var allowedChoices = ['your_choice_value1', 'your_choice_value2']; // Replace with the values you want to keep
var options = g_form.getControl(fieldName).options;
for (var i = options.length - 1; i >= 0; i--) {
var optionValue = options[i].value;
if (allowedChoices.indexOf(optionValue) === -1) {
g_form.removeOption(fieldName, optionValue);
}
}
}