Hide Choice option of multiple choice variable in service catalog

Apoorva2
Kilo Contributor

Hi,

I have to hide choice option from multiple choice variable in catalog item

but my code is not working,here is my code :

function onLoad() {
g_form.removeOption('Select Type of request','disable_account');

}

 

 

12 REPLIES 12

RaghavSh
Kilo Patron

g_form.removeOption('Select Type of request','disable_account');

 is "Select Type of request" the backend name of your variable, if not please use the backend name.

 

Please mark this correct/helpful accordingly.


Raghav
MVP 2023

Apoorva2
Kilo Contributor

Hi Raghav,

I used backend name though but its not working

 

The code is correct if you are using backend name for both variable and choice:

 

g_form.removeOption(<fieldName>, <choiceValue>);


Raghav
MVP 2023

Ankur Bawiskar
Tera Patron
Tera Patron

@Apoorva 

g_form.addOption() and g_form.removeOption() won't work on Multiple Choice variable

it only works for Select box with choices

you will have to use DOM manipulation for this which is not recommended.

For native this should work

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

for portal you will have to use something using class

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader