Scoped app: get user roles

aklimenko
Mega Expert

Hi

How can I get a list of user roles from scoped app script?

Scoped GlideUser and GlideSession do not have getRoles() unlike non-scoped versions

Thank you

1 ACCEPTED SOLUTION

Cary5
Mega Expert

If this is server-side, you can query the sys_user_has_role table to retrieve a list of roles for the user. I've built a custom app in fuji recently but didn't have a need for that particular function but that should be one way to do it. If it is client side, you could do an ajax call. I had issues using .isMemberOf() so I had to manually query the sys_user_grmember table to find group membership.


View solution in original post

3 REPLIES 3

Cary5
Mega Expert

If this is server-side, you can query the sys_user_has_role table to retrieve a list of roles for the user. I've built a custom app in fuji recently but didn't have a need for that particular function but that should be one way to do it. If it is client side, you could do an ajax call. I had issues using .isMemberOf() so I had to manually query the sys_user_grmember table to find group membership.


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Oleksil,



Here is the script to print the role name for the current logged in user.


var gr = new GlideRecord('sys_user_has_role');


gr.addQuery('user.user_name', gs.getUserDisplayName());


gr.query();


while(gr.next())


{


gs.addInfoMessage(gr.role.name); //prints the role name


}


Thank you, guys, for fast response!