We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

server equivalent of hasroleExactly

sreedharkaliset
Mega Expert

Hi,

Is there a server equivalent of g_user.hasRoleExactly

gs.hasRole returns true for admin and userHasRoleExactly works only client side

 

Regards,

Sreedhar

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

Hi Sreedhar,

you don't have server side function for that; use below code and store it in some script include; then you can call this and re-use it like from every server side script

hasRoleExactlyServerSide: function(){

var au = new ArrayUtil();
var roles = gs.getSession().getRoles() + ''; 
var roleArray = roles.split(","); 
var isRolePresent = au.contains(roleArray, role); 

return isRolePresent;

}

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

10 REPLIES 10

You're absolutely right!  That's a great point.  It could also be !=-1, but >0 is not going to work if that role is the first one in the list.