- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2021 05:06 PM
Hi i need to hide/show one option on the multiple choice variable based on other field (the other field is department, so when the department field has Field Service in it the option should hide otherwise show other times), Below is the CS, but it does not hide/show the Keyboard & Mouse option.
variable: department, where the department is Field Service (need contains Field Service)
multi choice variable: type
option value and display name: accessories - Keyboard & Mouse
script onchange on department:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.removeOption('type', 'accessories ', 'Keyboard & Mouse');
return;
}
if (g_form.getValue('department').indexOf('Field Service') > -1) {
g_form.removeOption('type', 'accessories ', 'Keyboard & Mouse');
}else {
g_form.addOption('type', 'accessories ', 'Keyboard & Mouse');
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2021 10:31 PM
I have found the answer: addOption, removeOption does not work on Multiple choice type variable, i have changed it to Select Box type and it works fine now.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2021 05:48 PM
Hi Sam,
When posting on the community try to include the issue you're having / exactly what isn't working within your script.
From your script, you need to use g_form.getDisplayValue() to get the text value, not the sys_id.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.removeOption('type', 'accessories ', 'Keyboard & Mouse');
return;
}
if (g_form.getDisplayValue('department').indexOf('Field Service') > -1) {
g_form.removeOption('type', 'accessories ', 'Keyboard & Mouse');
}else {
g_form.addOption('type', 'accessories ', 'Keyboard & Mouse');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2021 06:38 PM
Hi Kieran,
Thanks for the response and advise, however, in the post i mentioned i am trying to hide the option with the script i have put and i am implying that the hide is not working with my script, but anyway i have updated the post. And adding getDisplayValue does not work as well.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2021 07:50 PM
throw in the following, outside any if statements, to see if the script is correctly running and returning the expected value.
console.log(g_form.getDisplayValue('department'));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2021 10:31 PM
I have found the answer: addOption, removeOption does not work on Multiple choice type variable, i have changed it to Select Box type and it works fine now.