How to filter non-itil users

shaik_irfan
Tera Guru

How to take report of users who dont have itil role but has certificaton role, when i filter as role is not itil & role is certification i can see both since 1 condition is matching

1 ACCEPTED SOLUTION

bernyalvarado
Mega Sage

Hi Shaik shaik.irfan



Run the following script as a background script and you will get a list of all names of folks that have the certification role but not the itil role.



var gr = new GlideRecord('sys_user_has_role');


gr.addEncodedQuery('role.name=certification');


gr.query();


while(gr.next()){


  var gr2 = new GlideRecord('sys_user_has_role');


  gr2.addEncodedQuery('user=' + gr.user.sys_id + '^role.name=itil');


  gr2.query();


  if (!gr2.hasNext()){


      gs.print(gr.user.getDisplayValue() + ' ' + gr.role.getDisplayValue());


  }


}



disclaimer: i did this script while in meetings It's accurate but is not intended to be elegant



Thanks,


Berny


View solution in original post

6 REPLIES 6

bernyalvarado
Mega Sage

I hope this helps


This one works