Create a dynamic query to return all tickets opened by members of a specific group

geeerard
Giga Guru

I'm unsure if this is possible, but, we have a user who would like to view all tickets opened by members of a specific group. So, the user could specify which group they wanted, and it would show all the tickets opened by all members of that group. I believe it could be an additional requirement to specify whether the ticket is open/closed, but I'm stuck on this first portion as I'm not sure it can be done!

My attempt to achieve this was to use a business rule "getGroupMembers," and create a report using something similar to this JS call: where Opened By IS javascript:getGroupMembers(<group name>)

Apologies in advance if this is a duplicate; and I'm just getting into Service Now within the past month, so my experience is still limited! Thank you to anyone who could possibly point me in the right direction, your help is much appreciated!

1 ACCEPTED SOLUTION

tanumoy
Tera Guru

Below is the dynamic filter Options I have created for the same purpose:



From navigation panel, System Definition --> Dynamic Filter Options --> Click New



Capture.JPG



Now in the filter condition, if is(dynamic) is selected then you will have an option of the dynamic filter.



Capture.JPG



Script Include Code:



function getMyGroupMembers(){


      var myGroups = gs.getUser().getMyGroups();


      var groupsArray = new Array();


      var it = myGroups.iterator();


      var i=0;


      var groupMemberArray = new Array();


      while(it.hasNext()){


              var myGroup = it.next();


              //Query for group members


              var grMem = new GlideRecord('sys_user_grmember');


              grMem.addQuery('group', myGroup);


              //Only return active users


              grMem.addQuery('user.active', true);


              grMem.query();


              while(grMem.next()){


                      //Add to user sys_id to array


                      groupMemberArray.push(grMem.user.toString());


              }


              i++;


      }


      return groupMemberArray;


}


View solution in original post

7 REPLIES 7

sergiu_panaite
ServiceNow Employee
ServiceNow Employee

I think one way of doing this is by using a Dynamic Filter option:



Create a dynamic filter option



with a script filter:



Create scripted filters



Regards,


Thank you Sergiu! I actually didn't even think of using a dynamic filter, so thank you very much for this!


tanumoy
Tera Guru

Below is the dynamic filter Options I have created for the same purpose:



From navigation panel, System Definition --> Dynamic Filter Options --> Click New



Capture.JPG



Now in the filter condition, if is(dynamic) is selected then you will have an option of the dynamic filter.



Capture.JPG



Script Include Code:



function getMyGroupMembers(){


      var myGroups = gs.getUser().getMyGroups();


      var groupsArray = new Array();


      var it = myGroups.iterator();


      var i=0;


      var groupMemberArray = new Array();


      while(it.hasNext()){


              var myGroup = it.next();


              //Query for group members


              var grMem = new GlideRecord('sys_user_grmember');


              grMem.addQuery('group', myGroup);


              //Only return active users


              grMem.addQuery('user.active', true);


              grMem.query();


              while(grMem.next()){


                      //Add to user sys_id to array


                      groupMemberArray.push(grMem.user.toString());


              }


              i++;


      }


      return groupMemberArray;


}


Thank you @Tanumoy! Do you have the ability to specify which group you want to see results for? I believe this is almost what we're attempting to achieve, minus the specifying which group I want to run the report as. Thanks!