Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get all incidents based on caller group

soumya17
Tera Contributor

Hi,

I want to display all incidents that are created by my group members.

for eg: group A has 10members , so what all incidents are created by these 10members  i need to see them

 

How can i achieve this?

 

Thanks

1 ACCEPTED SOLUTION

Pavankumar_1
Mega Patron

Hi @soumya17 ,

created script and call it on the sysid field on the module.

1. Script Include:

var getMyGroupIncidents = Class.create();
getMyGroupIncidents.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getIncidnets: function() {
        var users = [];
        var groups = [];
        var incidents = [];
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('user', gs.getUserID()); //get logged in user sysid
        gr.query();
        while (gr.next()) {
            groups.push(gr.group + '');
        }
        var grMem = new GlideRecord('sys_user_grmember');
        grMem.addQuery('group', 'IN', groups); //add group sysid
        grMem.query();
        while (grMem.next()) {
            users.push(grMem.user + '');
        }
        var inc = new GlideRecord('incident');
        inc.addQuery('caller_id', 'IN', users);
        inc.query();
        while (inc.next()) {
            incidents.push(inc.sys_id + '');
        }
        return incidents;
    },

    type: 'getMyGroupIncidents'
});

Screenshot:

Screenshot (738).png

2. Create a module and call above script include on it.

Screenshot (740).png

javascript:new getMyGroupIncidents().getIncidnets()

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

View solution in original post

13 REPLIES 13

Hi @Pavankumar_1 

I want to get all incidents that are created by logged in user group members ..

i need to create one module and when user click on it he should see all tickets that are created by himself and all his group members...

 

 

for eg: A is part of 2groups which has 5, 5 members each..

so when A logged in he should see all tickets that are created by two group members..

 

Kalyani Jangam1
Mega Sage

Hi @soumya17 

I have created below background script as per your requirement and give one constant group sys_id

 

var gr=new GlideRecord("sys_user_grmember");
gr.addQuery('group','053cd11a5bda50106d8012300a81c721');// 1 group sys_id
gr.query();
while(gr.next()){
var grp=new GlideRecord("incident");
grp.addQuery('caller_id',gr.user);
grp.query();
while(grp.next()){
gs.info("Caller "+gr.user.name + ' ' + "Incident Number. "+grp.number);

}
}

 

Please try this and Mark Helpful or correct if it really help you

soumya17
Tera Contributor

I want to get all incidents that are created by logged in user group members ..

i need to create one module and when user click on it he should see all tickets that are created by himself and all his group members...

 

 

for eg: A is part of 2groups which has 5, 5 members each..

so when A logged in he should see all tickets that are created by two group members..

Pavankumar_1
Mega Patron

Hi @soumya17 ,

created script and call it on the sysid field on the module.

1. Script Include:

var getMyGroupIncidents = Class.create();
getMyGroupIncidents.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getIncidnets: function() {
        var users = [];
        var groups = [];
        var incidents = [];
        var gr = new GlideRecord('sys_user_grmember');
        gr.addQuery('user', gs.getUserID()); //get logged in user sysid
        gr.query();
        while (gr.next()) {
            groups.push(gr.group + '');
        }
        var grMem = new GlideRecord('sys_user_grmember');
        grMem.addQuery('group', 'IN', groups); //add group sysid
        grMem.query();
        while (grMem.next()) {
            users.push(grMem.user + '');
        }
        var inc = new GlideRecord('incident');
        inc.addQuery('caller_id', 'IN', users);
        inc.query();
        while (inc.next()) {
            incidents.push(inc.sys_id + '');
        }
        return incidents;
    },

    type: 'getMyGroupIncidents'
});

Screenshot:

Screenshot (738).png

2. Create a module and call above script include on it.

Screenshot (740).png

javascript:new getMyGroupIncidents().getIncidnets()

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar