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.

get incident count by caller wise and display p1 incident numbers

Soma Sekhar M
Tera Contributor

Scenario : Open the background script and write a code to get the count of incidents by the caller and print incident numbers as well if priority is P1?

 

Script : 

var incgr=new GlideAggregate('incident');
incgr.addAggregate('COUNT','caller_id');
incgr.query();
while(incgr.next())
{
var caller=incgr.getDisplayValue('caller_id');
var incpr=incgr.getValue('priority');
var count=incgr.getAggregate('COUNT','caller_id');
gs.print("For the "+caller+"the number of incidents are "+ count);
if(incpr==1);
{
gs.info(incgr.number);
}

}
gs.info(incgr.getRowCount());

 

I tried with the above solution but i am unable to get incident numbers could you please help on that ?

thanks in advance for your Help and support

1 ACCEPTED SOLUTION

OlaN
Giga Sage
Giga Sage

Hi,

You can try something like this:

var incgr = new GlideAggregate('incident');
incgr.addAggregate('COUNT','caller_id');
incgr.query();
while(incgr.next())
{
    var caller = incgr.getDisplayValue('caller_id');
    var count = incgr.getAggregate('COUNT','caller_id');
    gs.print("Caller "+ caller + " : count - " + count);

    var incPrio1GR = new GlideRecord('incident');
    incPrio1GR.addQuery('caller_id', incgr.getValue('caller_id'));
    incPrio1GR.addQuery('priority', '1');
    incPrio1GR.query();
    while (incPrio1GR.next()){
        gs.info('Prio 1 INC : ' + incPrio1GR.getValue('number'));
    }
}

View solution in original post

1 REPLY 1

OlaN
Giga Sage
Giga Sage

Hi,

You can try something like this:

var incgr = new GlideAggregate('incident');
incgr.addAggregate('COUNT','caller_id');
incgr.query();
while(incgr.next())
{
    var caller = incgr.getDisplayValue('caller_id');
    var count = incgr.getAggregate('COUNT','caller_id');
    gs.print("Caller "+ caller + " : count - " + count);

    var incPrio1GR = new GlideRecord('incident');
    incPrio1GR.addQuery('caller_id', incgr.getValue('caller_id'));
    incPrio1GR.addQuery('priority', '1');
    incPrio1GR.query();
    while (incPrio1GR.next()){
        gs.info('Prio 1 INC : ' + incPrio1GR.getValue('number'));
    }
}