- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2023 12:26 AM
Hi,
I wanted to apply an OR condition for multiple roles using gs.hasRole() method.
However, I have a confusion about the syntax for the same :
gs.hasRole('role1' , 'role2' ); or gs.hasRole('role1,role2');
I am getting different results from these two syntaxes. Let me know what the difference is, and which is the correct one to check whether role1 OR role2 is present for the user.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2023 12:50 AM
Hi @Adamya Singh Pa ,
Note : The hasRole() returns true, if the user has the role specified (e.g. hasRole(role)) OR the admin role.
Reference :- https://servicenowguru.com/scripting/user-object-cheat-sheet/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2023 12:50 AM
Hi @Adamya Singh Pa ,
Note : The hasRole() returns true, if the user has the role specified (e.g. hasRole(role)) OR the admin role.
Reference :- https://servicenowguru.com/scripting/user-object-cheat-sheet/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2023 12:58 AM - edited ‎03-10-2023 01:03 AM
Hi @Adamya Singh Pa ,
second one is correct. refer below
if(gs.hasRole('role1,role2,role3')){
//If user has anyof the role it will return true
}
or
if(gs.hasRole('role1') || gs.hasRole('role2')){
//If user has anyof the role it will return true
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2023 01:07 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2023 01:41 AM - edited ‎03-10-2023 01:42 AM
Are you sure about that? I came across a couple of articles with multiple roles as input.