Hide Question Choice in Select Box variable

nicolemccray
Tera Expert

If the user indicates 'request_for_new_hire = No, I want to hide the 'New Hire' option in the 'employee_type' select box.  My script is not working:

 

function onChange(control, oldValue, newValue, isLoading) {
 
 
 if (isLoading || newValue == '') {
  
  
  
  return;
 }
 
 //Type appropriate comment here, and begin script below
 var reqFor = g_form.getValue('request_for_new_hire');
 
 
 if(reqFor == 'No'){
  
  
  g_form.removeOption('employee_type', 'New Hire');
  
  
 }
 
 
 else{
  
  
  g_form.addOption('employee_type', 'New Hire');
  
  
 }
 
}

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron

Maybe you also want to change the values of your choices, it's not best practice to use spaces, stripes, etc.. So use new_hire, non_employee instead.

Just tested with code below, works fine:

function onChange(control, oldValue, newValue, isLoading) {
	
	if(isLoading || newValue == '') {
		return;
	}
	
	var reqFor = g_form.getValue('request_for_new_hire');
	
	if(reqFor == "No") {
		g_form.removeOption('employee_type', 'new_hire');
	} else {
		g_form.addOption('employee_type', 'new_hire', 'New hire');
	}

}

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

View solution in original post

5 REPLIES 5

Works great!  Thank you.