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

variable advanced reference qualifier example

Running transform maps asynchronously