What is the difference between hasRole() and hasRoleExactly() in servicenow.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2018 12:59 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2018 01:10 AM
Please refer the below link for detailed explanation
https://joshneri.us/serverside-hasroleexactly-in-servicenow/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2018 01:15 AM
Just an example use case for your understanding.
g_user.hasRole('itil') True if the current user has the role specified, false otherwise. ALWAYS returns true if the user has the 'admin' role.
So for admin it will return true
hasRoleExactly('itil') True if the current user has the exact role specified, false otherwise, regardless of 'admin' role.
Will return false for admin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2018 02:29 AM
Hi swarnikanandwana@gmail.com,
1) hasRole(String Role, Boolean include default )
Returns true if the current user has the specified role or the admin role.
2) hasRoleExactly(String Role, Boolean include default )
Returns true only if the current user has the specified role.
Refer this link :-
https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=c_GlideUserAPI
Mark it correct or helpful, if it works.
Warm Regards,
Priyanka
www.dxsherpa.com

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2018 01:20 PM
Hi Swarnika,
g_user.hasRole('client_script_admin');
This script checks to see if the currently logged in user has the capability to create and edit Client Scripts (client_script_admin role). Note that this script returns true not only when the currently logged in user has the role assigned but also if the currently logged in user has the admin role. The admin user has all roles implicitly assigned.
To test whether the currently logged in user has the role explicitly assigned, use the hasRoleExactly() method:
g_user.hasRoleExactly('client_script_admin');
Mark correct or helpful if it helps you.
Warm Regards,
Pranay Tiwari
| www.DxSherpa.com |