gs.getUser().isMemberOf not working properly on ACL

Khalnayak
Tera Guru

Hi all,

I have an ACL that  restricts certain field so it is only visible to change management.

This works, however the admins (including me)  could see the field restricted to the change_manager role, even though the admin overrides is unticked.

I read on a thread that if i use the below script it will then only show for users with that role.

However now, the field isnt showing for anyone, even users with change_manager role.

if (gs.getUser().isMemberOf('change_manager')) {

  answer = true;

}

else {

  answer = false;

}

find_real_file.png

 

what am i doing wrong here?

1 ACCEPTED SOLUTION

Willem
Giga Sage
Giga Sage

If you need them to have a specific role and not be admin you can do the following:

if (!gs.hasRole("admin") && gs.hasRole("change_manager")) {

  answer = true;

}

else {

  answer = false;

}

View solution in original post

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

iMemberOf is used to check if a user is a member of a group not necessarily if they have a role, and you need to pass in the sys_id of the group.  Roles should be applied to groups, not users anyway, so make sure your change management team members are in a group that has this role, then use the group sys_id in this ACL script

Willem
Giga Sage
Giga Sage

If you need them to have a specific role and not be admin you can do the following:

if (!gs.hasRole("admin") && gs.hasRole("change_manager")) {

  answer = true;

}

else {

  answer = false;

}

Kajal Goti
Mega Guru

Hi @Khalnayak ;

 

Are you working in scoped application ??

Please refer below thread

https://community.servicenow.com/community?id=community_question&sys_id=54050f2ddbd8dbc01dcaf3231f96...

 

https://community.servicenow.com/community?id=community_question&sys_id=bfa00765db98dbc01dcaf3231f96...

 

Please mark correct/helpful, If you find any help