Correct syntax for ACL checking group membership

Lon Landry4
Mega Sage

This is for Utah release (I have an all config version in Washington DC that works fine).

I have tried the following four ways


  1. var user = gs.getUser();
    answer = user.isMemberOf('IhaveTriedGroupSysID&GroupNameHere'); 

  2. answer = 
    gs.getUser().isMemberOf('IhaveTriedGroupSysID&GroupNameHere');

  3. gs.getUser().getUserByID(current.user).isMemberOf('IhaveTriedGroupSysID&GroupNameHere');
    //I have tried with and without wrapping sys_id or group name in quotes

  4. if
    (gs.getUser().isMemberOf('MyGroupName')) {
      answer = true;
    } else { answer = false;}
     
    Any ideas?
1 ACCEPTED SOLUTION

James Chun
Kilo Patron

Hey @Lon Landry4,

 

The first option should work for both cases - using the group name or its sys_id

e.g.

 

 

var user = gs.getUser();
answer = user.isMemberOf('cfcbad03d711110050f5edcb9e61038f');
answer = user.isMemberOf('Team Development Code Reviewers'); //both works

 

 
Are you certain it's the script that is causing the issue?
Maybe you have another condition (such as role) or another ACL that is interfering with your ACL?
 
FYI, from Vancouver, you can use what's called Security Attribute within your ACL - https://docs.servicenow.com/bundle/washingtondc-platform-security/page/administer/contextual-securit...
 
Cheers
 

View solution in original post

7 REPLIES 7

nataliya_b
Tera Guru

did you get correct answer when you run it as background script?

you could try to do via function

 

answer = checkUser();

function checkUser() {

return gs.getUser().isMemeberOf(yougroupnamehere);

}

}

Nope - 

Javascript compiler exception: missing ; before statement (null.null.script; line 3) in:

sorry, there is extra }, please remove it

I caught the extra } earlier...
error message from background scripts is 

Javascript compiler exception: missing ; before statement (null.null.script; line 3) in: