- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2021 04:43 AM
Hi,
My requirement is I need to count number of incidents with some assignment group and if there is only one incident with that perticular assignment group then I require that incident's sys_id . I don't want to use getRowCount(). I want to use only GlideAggregate. I have used the below script in my PDI but I did not get what I want.
Can Anybody help me on this.
var count = new GlideAggregate('incident');
count.addQuery('assignment_group','36c741fa731313005754660c4cf6a70d'); // Only one incident is there with this group
count.addAggregate('COUNT');
count.query();
var incidents = 0;
if (count.next())
incidents = count.getAggregate('COUNT');
gs.info(incidents); // 1
gs.info(count.getUniqueValue()); // null
gs.info(count.getValue('sys_id')); // no result
gs.info(count.sys_id.toString()); // no result
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2021 05:55 AM
Well doing some more play around I was able to get the sys_id. Please find the code below:
var count = new GlideAggregate('incident');
count.addQuery('assignment_group', '36c741fa731313005754660c4cf6a70d'); // Only one incident is there with this group
count.addAggregate('COUNT', 'sys_id');
count.query();
var incidents = 0;
if (count.next())
incidents = count.getAggregate('COUNT', 'sys_id');
gs.info(incidents); // 1
if(incidents==1) //validate if there is only one incident
gs.info('Sys_ID : ' + count.sys_id.toString());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2021 04:48 AM
Hi
Try this
var count = new GlideAggregate('incident');
count.addQuery('assignment_group','36c741fa731313005754660c4cf6a70d'); // Only one incident is there with this group
count.addAggregate('COUNT');
count.query();
if (count.next()) {
var incidents = count.getAggregate('COUNT');
gs.info(incidents); // 1
gs.info(count.getUniqueValue());
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2021 04:50 AM
It's not possible to get Sys id using Glideaggregate.
Use GlideRecord class instead
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2021 04:58 AM
Hi
Try this
var ga = new GlideAggregate('incident');
ga.addEncodedQuery('assignment_group=36c741fa731313005754660c4cf6a70d');
ga.query();
if(ga.next()){
gs.info(ga.sys_id);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2021 05:03 AM
Hi,
you cannot get the record sys_id using GlideAggregate
you will have to do 1 more query
var count = new GlideAggregate('incident');
count.addQuery('assignment_group','36c741fa731313005754660c4cf6a70d'); // Only one incident is there with this group
count.addAggregate('COUNT');
count.query();
var incidents = 0;
if (count.next()){
incidents = count.getAggregate('COUNT');
gs.info(incidents); // 1
var inc = new GlideRecord('incident');
inc.addQuery('assignment_group', count.assignment_group);
inc.query();
if(inc.next()){
gs.info('INC sys_id' + inc.sys_id);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader