what is the difference between the hasRole(), hasRoles() and hasRoleExactly() methods in g_user()?

rani3
Kilo Contributor

I am not getting clarity while practicing this.  what is the difference between the hasRole(), hasRoles() and hasRoleExactly() methods in g_user()

1 ACCEPTED SOLUTION

Raghu Ram Y
Kilo Sage

Hello @rani,  

I will make you understand in simple words.

g_user.hasRole(' ')

1. This method return true if the current logged in user has the role which we have provided in (' ')  otherwise false.

2. It will always returns true if the user has the 'admin' role.

Ex: 1. Consider in the above method if you provide "itil" role and some "abc" user is loggedin to the instance and the user having 'itil' role then it returns true

2. If the user having admin role then also it returns true

 

g_user.hasRoles()  " This method  return true if current logged in user has any single role atleast.

Ex:  Consider in the above method if you provide "itil" ,"service desk" roles and some "xyz" user is loggedin to the instance and the user having either of 'itil' or 'service desk' role then it returns true

 

g_user.hasRoleExactly(‘ ’)  This method return true if current logged in user has role we which have provided in (' ')

Ex:  1. This method return true if the current logged in user has the role which we have provided in (' ')  otherwise false.

2. It will returns false even if the user having 'admin' role.

 

If my answer clarifies your doubt then please "Mark it as Correct/Helpful"

View solution in original post

7 REPLIES 7

Raghu Ram Y
Kilo Sage

Hello @rani,  

I will make you understand in simple words.

g_user.hasRole(' ')

1. This method return true if the current logged in user has the role which we have provided in (' ')  otherwise false.

2. It will always returns true if the user has the 'admin' role.

Ex: 1. Consider in the above method if you provide "itil" role and some "abc" user is loggedin to the instance and the user having 'itil' role then it returns true

2. If the user having admin role then also it returns true

 

g_user.hasRoles()  " This method  return true if current logged in user has any single role atleast.

Ex:  Consider in the above method if you provide "itil" ,"service desk" roles and some "xyz" user is loggedin to the instance and the user having either of 'itil' or 'service desk' role then it returns true

 

g_user.hasRoleExactly(‘ ’)  This method return true if current logged in user has role we which have provided in (' ')

Ex:  1. This method return true if the current logged in user has the role which we have provided in (' ')  otherwise false.

2. It will returns false even if the user having 'admin' role.

 

If my answer clarifies your doubt then please "Mark it as Correct/Helpful"

Gaurav Shirsat
Mega Sage

Hello 

@Hardit Singh  and Murthy both have provided my Article link to you.

didn't it help you?

do you still need any help?


Please Mark Correct and Helpful
Thanks and Regards
Gaurav Shirsat

Omender Singh
Tera Guru