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

My requirement was to get the Group members of my groups. So I have not specified any group name here. You have to play something with the above script include to get you requirement done.


Not working for me .. any help?


Try something like below in the script include.



            var groupMemberArray = new Array();


              var grMem = new GlideRecord('sys_user_grmember');


              grMem.addQuery('group', '<sys_id of the group you want>'); //here put the sys_id of the group you want.


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


              grMem.query();


              while(grMem.next()){


                      //Add to user sys_id to array


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


              }


      return groupMemberArray;




It should work. Let me know the result.