How to check whether the current user has particular role using that role's sysid?

kutvaram
Tera Expert

Hi All,

In ACL, how to check whether the logged in user has particular role?

I know we can achieve it by using the method "hasRole".Example - gs.hasRole("RoleName");

But, I want to check it by comparing it with Role Sys Id.

How to do that?

Any Ideas?

Thanks & Regards,

Ram Prakash

 

1 REPLY 1

Jon Barnes
Kilo Sage

You could have an ACL script like this if you want to do it that way. Make sure you put the role's sys_id in the yourRoleSysId variable below. then the script will tell you if that user has the role by sys_id

 

(function() {
  var yourRoleSysId = '';
  var gr = new GlideRecord('sys_user_has_role');
  gr.addQuery('role', yourRoleSysId);
  gr.addQuery('user', gs.getUserID());
  gr.setLimit(1);
  gr.query();
  return gr.hasNext();
})();