Hi Everyone, I need to grey out the select box choice from the variable. Like the choice should be visible but it should not be selectable

DhanaLakshmi7
Tera Contributor

 I need to grey out the select box choice from the variable. Like the choice should be visible but it should not be selectable.

Please can any suggest me what has to be done.

Even I have tried the below link but it is not working for me.

https://servicenowguru.com/scripting/client-scripts-scripting/removing-disabling-choice-list-options/

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@DhanaLakshmi 

I used this script and it worked for native and not portal

onLoad Client Script

function onLoad() {
	//Type appropriate comment here, and begin script below

	var control = g_form.getControl('drop_down'); // your variable name
	var options = control.options;
	for (var i = 0; i < options.length; i++) {
		var option = options[i];
		var ov=option.value;
		if (ov == 'apple') {
			control.options[i].disabled = 'true';
		}
	}
}

Native: It disabled the apple choice

find_real_file.png

Regards
Ankur

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

View solution in original post

15 REPLIES 15

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

there is no concept of disabling the choices in variable directly unless you use DOM manipulation which is not recommended.

You can remove the choices using g_form.removeOption('variableName', 'choiceValue');

where are you stuck?

Regards
Ankur

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

Ankur Bawiskar
Tera Patron
Tera Patron

@DhanaLakshmi 

I used this script and it worked for native and not portal

onLoad Client Script

function onLoad() {
	//Type appropriate comment here, and begin script below

	var control = g_form.getControl('drop_down'); // your variable name
	var options = control.options;
	for (var i = 0; i < options.length; i++) {
		var option = options[i];
		var ov=option.value;
		if (ov == 'apple') {
			control.options[i].disabled = 'true';
		}
	}
}

Native: It disabled the apple choice

find_real_file.png

Regards
Ankur

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

Hi Ankur,

 

Yes, this is working only for form view but not for the service portal. This can not be done for service portal?

Hi,

you might have to play with the HTML element and disable that

Regards
Ankur

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