OnLoad based on company need to hide choices of a field on form

Community Alums
Not applicable

Hi All, having a requirement, 

 

Need to hide choices of the 'State' field based on the company selection. 

need to try with onLoad script any suggestions.

 

Thanks.

1 ACCEPTED SOLUTION

Eswar Chappa
Mega Sage
Mega Sage

Hi @Community Alums  with an Onload client script  as below you can achieve it, I had used Location instead of Country in the below , I had hided Canceled option in the below example

 

function onLoad() {
if (g_form.getValue('location') == '3e94ed7437d0200044e0bfc8bcbe5d9b') {

	g_form.removeOption('state','8');
	
	}  
}

 

Eswar4_0-1692170766896.png

Eswar4_1-1692170973120.png

 

Cheers, hope that helps  /Eswar

*** Please mark as "Correct" or "Helpful" as appropriate ***

View solution in original post

7 REPLIES 7

Eswar Chappa
Mega Sage
Mega Sage

Hi @Community Alums Please find the below community article for the solution

 

https://www.servicenow.com/community/developer-forum/ui-policy-to-hide-choice-value-based-on-something-another-field/m-p/1729680#M386606

 

Cheers, hope that helps  /Eswar

*** Please mark as "Correct" or "Helpful" as appropriate ***

Samaksh Wani
Giga Sage
Giga Sage

Hello @Community Alums 

 

Ideally it should be done on onChange CLient Script. As when you change the company selection, State field will filter out choices.

 

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

 

use the above line in Your script for hiding the choices.

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

Community Alums
Not applicable

Company field is not editable one, its a default value and readonly on the form when its load. 

so we can try with onload ?

and company is a reference field so need to try with the getreference type.

 

Hello @Community Alums 

 

In that case Write onLoad() Script :- 

 

 

function onLoad() {
if (g_form.getValue('company') == 'sys_id') {

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

 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh