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

isMemberOf function in client script

Michael Bachme1
Kilo Guru

I'm trying to get certain options in the State field to hide if the current user is not a member of a group. The script I have so far is as follows:

function onLoad() {

  var usr = g_user.getUserID();

  var gate = g_form.getValue('u_field');

  if (gate == 'true' && !usr.isMemberOf('GROUP')){

      g_form.removeOption('state', '3'); //closed complete

      g_form.removeOption('state', '4'); //closed incomplete

      g_form.removeOption('state', '7'); //closed skipped

    }

}

How do I get the opposite of 'isMemberOf'? I was thought it was an exclamation point (i.e. !usr.isMemberOf('group').

Thoughts?


Thanks in advance.

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee

Step 1: Create a display Business rule with script as. Place the below script between function templates in script body.


g_scratchpad.grp = gs.getUser().isMemberOf('PASS GROUP NAME HERE');  



Now update the client script as


function onLoad() {


  var usr = g_user.getUserID();


  var gate = g_form.getValue('u_field');


  if (gate == 'true' && !g_scratchpad.grp){


      g_form.removeOption('state', '3'); //closed complete


      g_form.removeOption('state', '4'); //closed incomplete


      g_form.removeOption('state', '7'); //closed skipped


    }


}



View solution in original post

15 REPLIES 15

nthumma
Giga Guru