We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

help with onLoad client script

Jen11
Tera Expert

I have a catalog item with the following checkbox.  My requirement is to create onLoad client script that is if the 'Requested for' job code is 40 and above to show the Copilot checkbox, otherwise hide the field.  Can someone help me with that client script? 

Jen11_0-1755539460158.png

 

7 REPLIES 7

RaghavSh
Giga Patron

g_form.setVisible(“var_name”,false);
var code = g_form.getReference(“requested_for”,callback);

 

function callback(code)

{
if (code.job_code>=40)

g_form.setVisible(“var_name”, true);

}

Note: please verify and replace the field and variable names.


Raghav
MVP 2023
LinkedIn

Its_Azar
Kilo Sage

Hi @Jen11 

 

Give this a try 

function onLoad() {

g_form.setVisible('copilot_checkbox', false);


g_form.getReference('requested_for', function(user) {
if (user && user.job_code >= 40) {
g_form.setVisible('copilot_checkbox', true);
}
});
}

 

 

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.

Kind Regards,
Azar
Serivenow Rising Star
Developer @ KPMG.

Jen11
Tera Expert

I actually miss spoke, I meant approval lever is 40 and above and job code. 

So where is that approval lever field? On user table? If yes same code will work you just need to use the correct field.


Raghav
MVP 2023
LinkedIn