- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2021 09:41 PM
I am not getting clarity while practicing this. what is the difference between the hasRole(), hasRoles() and hasRoleExactly() methods in g_user()
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2021 01:13 AM
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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2021 01:13 AM
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"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2021 11:51 PM
Hello
didn't it help you?
do you still need any help?
Please Mark Correct and Helpful
Thanks and Regards
Gaurav Shirsat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2022 06:46 PM