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

@soumya17 ,

 

You're saying that a single caller could belong to numerous groups if we use this filter. Let's assume a caller is assigned to two separate incidents and that belongs from the two different groups and those incidents would be the part of the coming results. Am I understanding correct?
If SO that check is not possible because in the caller field, we don't have the information regarding "assignment_group", it will return all the data w.r.t to that caller

yes..

what i am trying to achieve is..

i created a custom role.. and that role users can only create incidents.

So when login user is custom role user then he should have write access to all incidents that are created/opened by custom role users.

Read access to all incidents that are opened by itil ,manager ..etc roles.

 

so first tried of accessing all grmembers created incidents.

Hi @soumya17 ,

try below script

var users = [];
var groups = [];
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 + '');
}
gs.info("Groups  are " +groups);
var grMem = new GlideRecord('sys_user_grmember');
grMem.addQuery('group','IN',groups);//add group sysid
grMem.query();
while (grMem.next()) {
    users.push(grMem.user + '');
}
gs.info("Users  are " +users);
var inc=new GlideRecord('incident');
inc.addQuery('caller_id','IN',users);
inc.query();
while(inc.next()){
gs.info("ALL incidents created by your groups " +inc.number)
}

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

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 ,

use below script I have tried in background script to get the incidents. Use this script as per your requirement.

var users = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addEncodedQuery("group=8a5055c9c61122780043563ef53438e3");//add group sysid
gr.query();
while (gr.next()) {
    users.push(gr.user + '');
}
gs.info(users);
var inc=new GlideRecord('incident');
inc.addQuery('caller_id','IN',users);
inc.query();
while(inc.next()){
gs.info("ALL incidents created by your group " +inc.number)
}

 

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