- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2020 05:55 AM
Hello!
In a catalog item, i have 2 variables, VAR A and VAR B.
Var A has 2 options - Option 1 and Option 2
VAR B has 2 options, Option 1 and Option 2
The requirement is if the user selects VAR A = Option 1, VAR B will only show Option 2.
// newValue is VAR_A
if (newValue == 'Option 1')
g_form.removeOption('VAR _B', 'Option 1');
else if (newValue == 'Option 2')
g_form.removeOption('VAR _B', 'Option 2');
This works if I change VAR A to Option 1.
BUT when I change the VAR A selection to Option 2, all of the VAR B values disappear.
I used an On Change catalog client script for this.
Please help!
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2020 06:03 AM
please try this updated script
1) first clear all the options
2) then add respective option
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.clearOptions('VAR _B');
if (newValue == 'Option 1') {
g_form.addOption('VAR _B', 'Option 2', 'Option 2 Label');
}
if (newValue == 'Option 2') {
g_form.addOption('VAR _B', 'Option 1', 'Option 1 Label');
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2020 05:59 AM
try below
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == 'Option 1') {
g_form.removeOption('VAR _B', 'Option 1');
}
if (newValue == 'Option 2') {
g_form.removeOption('VAR _B', 'Option 2');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2020 06:03 AM
please try this updated script
1) first clear all the options
2) then add respective option
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.clearOptions('VAR _B');
if (newValue == 'Option 1') {
g_form.addOption('VAR _B', 'Option 2', 'Option 2 Label');
}
if (newValue == 'Option 2') {
g_form.addOption('VAR _B', 'Option 1', 'Option 1 Label');
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2020 06:31 AM
This works!
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2020 06:40 AM
You are welcome
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader