How to check if current user is having at least one role from list field?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2023 04:07 AM
Hi all,
I have a table on which there is list type of field storing user roles.
I want to GlideRecord on that table with query that logged in user should have at least one role from that list.
I am trying in background script but not sure how to do this
var gr= new GlideRecord('pa_dashboards');
gr.addQuery('u_roles_list', not sure what to add);
gr.query();
while(gr.next()){
gs.print('Dashboards are'+gr.name);
}
i have to add query only as there other or conditions as well
Please let me know if there is some workaround . Thanks!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2023 04:39 AM - edited 11-21-2023 04:41 AM
Hi @BijoyDeb ,
Please try this code below
var gr = new GlideRecord('pa_dashboards');
gr.query();
while (gr.next()) {
var roleList = gr.u_roles_list.split(',');
if (roleList.length > 0) {
for (var i = 0; i < roleList.length; i++) {
if (gs.getUser().hasRole(roleList[i]))
gs.info('Dashboards are' + gr.name);
break;
}
}
}
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 02:06 AM
Hi @piyushsain ,
I want to use 2 or conditions with this as well
How can i do that , means for role this will work but
var gr= new GlideRecord('pa_dashboards');
gr.addQuery('u_groups', grp).addOrCondition('u_roles', role).addOrCondition();
gr.query();
while(gr.next()){
gs.print('Dashboards are'+gr.name);
}
Now, here i need to check with role logic as well which you answered
I'll appreciate if you give some idea here
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 02:17 AM
I did not get your question can you please elaborate
Regards,
Piyush Sain