Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to hide "options" in a checkbox variable

Alessa
Mega Guru

Dear community, I need help:

I have created a service where I use the checkbox variable:

find_real_file.png

When I go to the catalog I see that this variable has a default value "options" that I want to delete, but I don't know how to do it.

find_real_file.png

I read an article in ServiceNow community where they said that you have to create a client script and add the sys id of the variable, but for some reason it does not work:

find_real_file.png

 

Any hints?, can anyone help me with this or tell me what mistake I am making?

Thanks in advance.

 

4 REPLIES 4

Sai122
Giga Guru

Hi,

You have to write an onLoad client script after you create a label to hide it.

 

$('label_IO:7817abedad4c3100dd49a5edb9ba2a38').hide(); //Replace this with the sys_id of the label you created.

 

NOTE: To hide a label first you have to create a label and then write a client script to hide it.

 

 

 

Regards,

Sai

davidpridemore1
Tera Contributor

To do this without DOM manipulation (if you're okay with a slight white space where the 'Options' string once was), you can create a label variable and do the following:

g_form.setLabelOf('hide_me_0','');

 The Question field is mandatory on labels, but this will let you hide the label value without hiding the checkboxes. setVisible and setDisplay on the labels hides all the associated checkboxes as of the Tokyo version.

Hey David,

 

Where should I apply the below:

g_form.setLabelOf('hide_me_0',''); 

 I'm experiencing the same issue. I've tried to put my variables in a container as well as tried Client script but it doesn't seem to work.

Hey sorry for the delay in response. Came back to this to try and remember how I did it.

 

This is in an onLoad client script. This does not work in native view, but will work in portal:

 

function onLoad() {
	// Hiding the labels to achieve the label-less checkboxes underneath the country selection
	// This doesn't work. Hides all the checkboxes.
	// 	g_form.setVisible('hide_me_0', false);
	// 	g_form.setVisible('hide_me_1', false);
	// This also doesn't work. Hides all the checkboxes.
	// 	g_form.setDisplay('hide_me_0', false);
	// 	g_form.setDisplay('hide_me_1', false);
	// This works but leaves a space between the checkboxes and the master label/container 
	g_form.setLabelOf('hide_me_0', '');
	g_form.setLabelOf('hide_me_1', '');
}

 Make sure UI Type is set to All or Mobile/Service Portal. There's probably a way to do it on the SC view as well but I haven't encountered that requirement. Might require DOM manipulation for that.