Remove option from a Multiple Choice variable without deleting it.

mattystern
Kilo Sage

Hello,

I have been tasked with hiding an option in a multiple choice list. I found there was not an "Active" button to work with, so I started writing a catalog client script to do this. However, I am having difficulty getting this script to work. 

For purposes of an example (and because I was going insane trying to get it to work on Friday), I went ahead and created a new catalog with a variable called "Choice Testing," a multiple choice list with options "Red", "Green", and "Blue"

find_real_file.png

Next, I created a catalog client script in order to remove the "Red" variable. According to this post, it is wise when using an "onLoad" client script to verify that the option is not selected by default in your script which is why the "If" statement exists. 

find_real_file.png

Alas, after the script our friend "Red" still loads on the form.

find_real_file.png

I tried implementing the function "Disable Option" into my System UI -> UI Scripts in accordance with the post I referenced earlier. Unfortunately, this did not also work to hide the variable. 

Can I get some pointers on how to make this work? Hopefully it is just some silly mistake on my part. Any help is appreciated! 

 

1 ACCEPTED SOLUTION

I believe removeOption() doesn't work for removing options from Multiple Choice type of variable. You can use it in Select Box type of variable.

View solution in original post

17 REPLIES 17

One of our departments has a service catalog they they use. They currently have no need for one of the options on their form, but they could see a use for it in the future.

This option also has many catalog ui policies and variables linked to it, so it would be time consuming to re-construct if they needed it again.

On items that have been ordered with that value you would now see the value and not the text.  Also, you won't be able to search by that value.

Cuong Phan
Kilo Sage

Hi,

 

Get Controls can hide option, it works for me.

 

Step1. Get Controls to get multiple NodeList

find_real_file.png

Step2. Dowalk to upper parent node and hide

g_form.getControls('multiple_choices').forEach(function(e) {
		if (e.value == 'yes')
			e.parentElement.style.display = 'none';
	});

 

Mark  Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.

 

Cuong Phan

DXC Consultant.

 

Regards,
Cuong Phan
ServiceNow Technical Lead

So I assume that there is no way of just disabling some radio buttons in a multiple choice form variable? Thanks!

Short answer is no. 

Longer one - There still is not an "Active" checkbox on question choices inside of variables which is a little bit of a pain. It also, from my experience, seems like g_form.removeOption() doesn't work on radio buttons. I just checked this 'testing' catalog I have - it still doesn't work on multiple choice variable type [on Orlando release now]. It can work if you convert the variable to a select box and there really isn't any disadvantage to doing this.