- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2023 10:46 PM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2023 02:38 AM
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'));
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2023 02:38 AM
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'));
}
}