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/

Comments

  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

    ReplyDelete

Post a comment

Popular posts from this blog

Running transform maps asynchronously

Post a command to the ECC queue for the mid server to initiate a powershell file copy

GlideRecord setValue