
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2017 01:07 AM
Hi everyone.
When creating view rules, I'd normally go for hasRole to specify a view for an ITIL user for example.
But, how do I target users who have no roles, in my scripts?
Is it hasRole('NULL'), hasRole($null) or perhaps hasRole('')?
Or is it better to use a fourth way?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2017 01:17 AM
Here:
how to check for null roles using gs.hasRole() function
gs.getUser().getUserRoles().toArray().length==0 //this means current user does not have any roles.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2017 01:17 AM
Hello Jacob,
I believe the function you're looking for is "hasRoles()".
hasRoles()
|
http://wiki.servicenow.com/index.php?title=GlideUser_(g_user)#hasRoles
Kind regards,
Simon Liang

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2017 01:20 AM
Thanks, but I wanted to opposite. When the user doesn't have ANY roles
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2017 01:24 AM
Hello Jacob,
Then you would need to negate your condition:
if (!user.hasRoles()) {
// do something
}
Kind regards,
Simon Liang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2017 01:17 AM
Here:
how to check for null roles using gs.hasRole() function
gs.getUser().getUserRoles().toArray().length==0 //this means current user does not have any roles.