Comparison of Roles
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2016 05:19 AM
Hi Everyone
Using the following code I am capturing the sys_id of the logged in user in an array.
var gr11 = new GlideRecord('sys_user_role');
gr11.addQuery('name', gs.getUser().getRoles());
gr11.query();
gr11;
var qry2;
var objArray2 = [];
while(gr11.next()) {
objArray2.push(gr11.sys_id.toString());
}
We have a role field in "sys_app_module" table of type "User Roles".
How can I compare the roles field of sys_app_module table with the values(sys_ids) in an array?
Please assist me on this.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2016 07:08 AM
Madhusudan, are you trying to check if the current user has at least one of the roles specified for a particular sys_app_module entry?
If so you could use, something like
var appId = ''; // Sys id of app
var gr = new GlideRecord('sys_app_module');
gr.get(appId);
var roles = gr.getValue('roles'); // this would return something like 'itil,project_user'
var hasAccess = gs.getUser().hasRole(roles);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2016 09:50 AM
Hi
Thanks for the reply.
I don't want to hardcode with sys_id because application changes here.
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2016 08:06 AM
Hey Madhu S,
Can you please tell us the exact requirement you are trying to achieve so that we can assist you further.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2016 09:57 AM
Hi Pradeep
I want to display the modules on the page based on the logged in user role.
So I want to compare logged in user role with roles field of module.
var gr = new GlideRecord('sys_app_module');
gr.addQuery('active',true);
gr.addQuery('roles',???) //comparing logged in user role with roles field of module here
Please assist me on this.
Thanks in advance.