How to check if current user is having at least one role from list field?

BijoyDeb
Tera Contributor

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!!

3 REPLIES 3

piyushsain
Tera Guru
Tera Guru

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;
        }
    }
}

 

 

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

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

I did not get your question can you please elaborate

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain