Difference between getRoles() and sys_user_has_role
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2016 03:12 AM
Using getRoles() returns 16 roles on my user but when I query sys_user_has_roles for my current user object I get 21 roles back - which is correct.
But can anybody explain why there's a difference - why does getRoles() not return ALL roles ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2016 03:20 AM
Hi Kim,
When you query your own user you will get all the records in the sys_user_has_role table. It could be possible that you have multiple records in there that assign you the 'itil' role.
The getRoles() function returns a distinct of the roles. So there are no duplicates in the returned data.
Kind regards,
Thijs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2016 03:41 AM
Hi thijsdaemen,
Yes I can see what you mean with a role like 'itil' that have duplicate records in sys_user_has_role. But I have another role called ITBackup and this role is not in the list from getRoles() but it appears in sys_user_has_role table. Do you know other "filters" in the getRoles function ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2016 04:36 AM
Hi Kim,
You are using gs.getSession().getRoles() to get the roles? I assume you are using contextual security, so this would be the correct syntax.
Kind regards,
Thijs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2016 03:23 PM
I have the same problem. I have queried several cases now where the results I get within the ServiceNow interface are different to the results if I query the sys_user_has_role table directly on a replicated copy of the table. I have tried all of the obvious things like active flags, etc. and still I have the same results. The getRoles function and the visibility of the data through the UI must be restricted in some way.