Onchange of varaibles remove option is not working

1234567789hrebn
Tera Expert

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 

11 REPLIES 11

Mark Roethof
Tera Patron
Tera Patron

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

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

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

}

}

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

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

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

---

LinkedIn

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn