IIs there a gs.hasRole() equivalent for users other than the currently logged in user?

oacp
Kilo Contributor

I'm looking for a way to easily determine if a user referenced on a record has a particular role within one of my scripts.

Since gs.hasRole() can only be used to determine if the currently logged in user has the specified role, the only method I know of is to glide the sys_user_has_role table querying for the referenced user and specified role.

Is there a gs.hasRole() equivalent that can be used to determined if a user other than the currently logged in user has a specified role rather than having to glide the sys_user_has_role table?

1 ACCEPTED SOLUTION

Shahed Shah1
Tera Guru

You can play around with the GlideUser API, where you can create a variable for a user like:


var user = GlideUser().getUser('fred.luddy');



Then you can use the hasRole function for that user


gs.print(user.hasRole('admin'));



Documentation for GlideUser:


https://developer.servicenow.com/app.do#!/api_doc?v=helsinki&id=c_GlideUserScopedAPI


View solution in original post

2 REPLIES 2

Shahed Shah1
Tera Guru

You can play around with the GlideUser API, where you can create a variable for a user like:


var user = GlideUser().getUser('fred.luddy');



Then you can use the hasRole function for that user


gs.print(user.hasRole('admin'));



Documentation for GlideUser:


https://developer.servicenow.com/app.do#!/api_doc?v=helsinki&id=c_GlideUserScopedAPI


Thank you for this, extremely helpful! I have been looking for a way to do this for a long time!