- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2019 09:54 PM
Hi,
I have a Display BR as below
g_scratchpad.uirole = gs.getUser().hasRole('ui_role');
and in Client scrpt on Load
alert(g_scratchpad.uirole);
when i impersonate to itil is user it is working perfectly fine but for admin even admin user dont have that role it is dsplaying as 'true'
Can anyone please help me it should dispaly as false for admin's too if the user dont have that role
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2019 10:16 PM
Hi there,
Have you also tried g_user.hasRoleExactly('itil');
See example here:
https://developer.servicenow.com/app.do#!/api_doc?v=newyork&id=r_GlideUser-hasRoleExactly_String
Note: this is already about Client Side. So you don't need to do this Server Side, using a Business Rule with scratchpad, and then Client Side.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2019 10:16 PM
Hi there,
Have you also tried g_user.hasRoleExactly('itil');
See example here:
https://developer.servicenow.com/app.do#!/api_doc?v=newyork&id=r_GlideUser-hasRoleExactly_String
Note: this is already about Client Side. So you don't need to do this Server Side, using a Business Rule with scratchpad, and then Client Side.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2019 10:23 PM
try now
if (gs.getUser().getRoles().indexOf('ui_role') > -1){
g_scratchpad.uirole = 'true';
}
client script:
alert(g_scratchpad.uirole);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2019 01:54 AM
Hi Shaik,
that is because admin inherits all the roles;
so even admin user would have that role as it gets inherited
try this to know if user has the exact role
no need for display business rule and scratchpad; in client side itself you can know whether user has exact role or not
function onLoad(){
alert(g_user.hasRoleExactly('ui_role'));
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2019 03:44 AM
Hi,
Please refer below link.
https://www.servicenowguru.com/scripting/user-object-cheat-sheet/
Thanks