What is the difference between hasRole() and hasRo... - ServiceNow Community

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

Swarnika1
Giga Expert

Can someone please explain me this.

6 REPLIES 6

DilipKumar DJ
Kilo Guru

Please refer the below link for detailed explanation

https://joshneri.us/serverside-hasroleexactly-in-servicenow/

 

DilipKumar DJ
Kilo Guru

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

 

Priyanka136
Mega Guru

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.

          Parameter(s):

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

find_real_file.png

www.dxsherpa.com

Pranay Tiwari
Kilo Guru

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 |