HasRolesExactly function

function gld_hasRoleExactly(role) {
var au = new ArrayUtil();
var roles = gs.getSession().getRoles() + '';
var roleArray = roles.split(",");
var isAuthorized = au.contains(roleArray, role);
return isAuthorized;
}//courtesy of https://joshneri.us/serverside-hasroleexactly-in-servicenow/


  1. Also with javascripts .includes()

    function gld_hasRoleExactly(role) {
    return gs.getSession().getRoles().includes(role);

    gs.print(gld_hasRoleExactly('itil')); //false
    gs.print(gld_hasRoleExactly('admin')); //true


Post a Comment

Popular posts from this blog

GlideRecord setValue

URL link in addInfoMessage

variable advanced reference qualifier example