GlideAggregate return wrong value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2024 12:06 AM
Hi all , Iam trying to get the count based on the query , but in system records its showing count as 534.
but when i run script in background its showing as 543. did i miss anything?
var totalCount = 0;
var count = new GlideAggregate('cmdb_sam_sw_install');
count.addEncodedQuery("discovery_model.u_software_name=c421a3e387e4d21075920d460cbb350b");
count.addAggregate('COUNT');
count.groupBy('installed_on');
count.query();
while (count.next()) {
totalCount = totalCount+1;
gs.info(count.getAggregate("COUNT")+ "--"+count.getValue("installed_on"));
}
gs.info("Total count: " + totalCount);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2024 12:15 AM
Hi Sharath807,
Can you please remove the "count.groupBy('installed_on')" and run again? Please mark my answer helpful if the issue is resolved.
Thank you and have a nice day!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2024 12:27 AM
Hi @Sharath807
Try with the below code
var totalCount = 0;
var count = new GlideAggregate('cmdb_sam_sw_install'); count.addEncodedQuery("discovery_model.u_software_name=c421a3e387e4d21075920d460cbb350b");
count.addAggregate('COUNT');
count.groupBy('installed_on');
count.query(); /
while (count.next()) {
var groupCount = count.getAggregate("COUNT");
count totalCount += parseInt(groupCount);
gs.info(groupCount + " -- " + count.getValue("installed_on"));
}
gs.info("Total count: " + totalCount);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2024 12:29 AM
@Sharath807 Please modify your script as follows.
var totalCount = 0;
var count = new GlideAggregate('cmdb_sam_sw_install');
count.addEncodedQuery("discovery_model.u_software_name=c421a3e387e4d21075920d460cbb350b");
count.addAggregate('COUNT');
count.groupBy('installed_on');
count.query();
if (count.next()) {
totalCount = count.getAggregate("COUNT");
}
gs.info("Total count: " + totalCount);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2024 01:41 AM
Hi @Sandeep Rajput its displaying as total count = 1,
but actual value should be 534