How to hide question choices on a service catalog item

Milan Hrdlicka
Kilo Contributor

I have a service catalog item containing 4 question choices.

I need 2 of these question choices hidden based on current user's logged in role.

The crucial thing is I am unable to check out how to hide thse fields even without the dependancy on a user's role.

I tried this:

g_form.removeOption('value','cym3');
g_form.removeOption('value','cym6');

'value' is question choice's value. I tried this in Catalog client script however it does not work.

I use Madrid instance.

Can anyone please help?

Thanks a lot!

Milan

 

 

14 REPLIES 14

checking 

Harsh Vardhan
Giga Patron

i checked you have used multiple choice type variable on catalog form. then in that case removeOption() will not work.  if you still want to hide them then you have to use DOM which is not a good practice and not a best approch to hide those option. i would suggest change the field type to Select Box.

 

either you convert the variable type as Select box , so you can create a dropdown option and then removeOption() will work. 

 

you can see if you want to hide the multiple choice type of variable choices then you have to use DOM manipulation which is not a good approach. 

function onLoad() {
alert('hey you !');
		
// g_form.removeOption('pack_type','cym3');
// g_form.removeOption('pack_type','cym6');
	


//Type appropriate comment here, and begin script below


var choice = document.getElementById("IO:0cf9e219db85330042bfe9c94896198a_0e3ae619db85330042bfe9c948961904").parentNode.parentNode; // Use the entire id so that you can hide particular choice.


if (choice){


choice.style.visibility="hidden";


choice.style.display="none";


}







}

Milan Hrdlicka
Kilo Contributor

Changed it to select Box and it works! 🙂

Appreciate your help and thank you for the additional piece of code as well...

Milan

glad i helped. kindly mark my answer as correct and close this thread. 

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