Onchange of varaibles remove option is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2019 02:19 AM
Hello All,
i have created onchange client script to remove option based other variable but it is not working as expected please provide your inputs on it below is my scenario.
Two Variables of type select box A and B
A has two choices x and y
B has two choices p and q
if we select x under A only p has to display for B
for y we need to display both values of B
i have created a script of onchange when we select x under A only one values is showing working fine but when changing back to y B has to display both values but it is not happening .
Please provide me with workaround
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2019 02:22 AM
Hi there,
Can you share what you have setup so far? I assume you are having multiple onChange Client Scripts for this? Have you also considered using UI Policies?
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2019 02:25 AM
hi i have created on change client script on change o variable A
if we select x to remove q option from B
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == 'x') {
g_form.removeOption("B", 'q');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2019 02:28 AM
Ah oke, so you are removing, but not adding them back? Is that already the issue?
g_form.addOption(1,2,3);
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2019 02:43 AM
See code below for Select Box A. Tested and works! I guess you can make Select Box B script yourself with this 🙂
function onChange(control, oldValue, newValue, isLoading) {
if(isLoading) {
return;
}
if(newValue != 'x') {
g_form.addOption('b', 'q', 'Q');
}
if(newValue == 'x') {
g_form.removeOption('b', 'q');
}
}
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field