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 fields through client script based on group?

Servicenow10
Kilo Guru

hi

i have to write one client script on load of chg req that :

if (logged in user is ammber of group ='abc') {

g_form.setDisplay('cab_required', true); //cab required field is a checkbox field
 var field = g_form.getValue('cab_required');
 if (field == true) {
 g_form.setValue('u_type', 'u_normal', 'Normal');

 }

 }

 

how to put this in syntax correctly

thanks

1 ACCEPTED SOLUTION

Hi,

Check the output and let me know what is it showing.

function onLoad() {
  var display = g_scratchpad.display;
  alert(display);
  if (display == 1) {
    alert("if1");
    g_form.setDisplay('cab_required', true);
    var field = g_form.getValue('cab_required');
    alert(field);
    if (field == true) { //is the syntax is proper
       
      g_form.setValue('u_type', 'u_normal', 'Normal');
    }
  } else {
    alert("else");
    g_form.setMandatory('cab_required', false);
    g_form.setVisible('cab_required', false);
  }
}

View solution in original post

10 REPLIES 10

Kunal Varkhede
Tera Guru

Hello,

 

One more thing i want to add. Use g_form.setDisplay() method because setDisplay() will reclaim the space if the field is hidden.

g_form.setDisplay('cab_required', true);

 

Please mark correct/helpful answer if it help you in any way.

Thanks,

Kunal