g_user.hasRoles question

servicetrout
Tera Expert

Running code below in a client script on form, not on a record producer.  The user has no Department or Division role, but does have a Unit role.

alert ("Starting");
var gUser = g_user.userID;
var Reviewer = g_user.hasRoles('Department','Division');
var personalRole = g_user.hasRole('Unit');
alert ("User: " + gUser +  " Reviewer: " + Reviewer + "  Unit Role :" + personalRole);

The last alert is showing the correct user (when I impersonate them). 

Reviewer is ALWAYS true, even though the user doesn't have those roles.

The personalRole is correct and has been tested for both true and false conditions.  

 Any idea why it isn't returning false for Reviewer?

 

 I've confirmed the user doesn't have either role (twice). 

1 ACCEPTED SOLUTION

Shishir Srivast
Mega Sage

g_user.hasRoles(); I believe it evaluates if current user has ANY role whether it's 'Department','Division' or ANY other role. If user has any role other than 'Department','Division' roles it should return true.

find_real_file.png

View solution in original post

6 REPLIES 6

Shishir Srivast
Mega Sage

g_user.hasRoles(); I believe it evaluates if current user has ANY role whether it's 'Department','Division' or ANY other role. If user has any role other than 'Department','Division' roles it should return true.

find_real_file.png

servicetrout
Tera Expert

Ah, got it, totally did not understand that.  Probably should name the method "hasAnyRole'. 

 

Found this works for what I was trying to accomplish. 

if (g_user.hasRoleExactly('Department') || g_user.hasRoleExactly('Division') || g_user.hasRoleExactly('Enterprise') ) {
   reviewer = true;
} else {
   reviewer = false;
}

 

Thank you for the quick reply. 

 

-G

Did you try hasRoleExactly with multiple roles? Both Department and Unit role?


Please mark this response as correct or helpful if it assisted you with your question.

yes, you can try multiple roles with hasRoleExactly().