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 09:30 PM
Hi @Tai Vu in my case i have a custom filed in discover model (discovery_model.u_software_name), so first i need to filter based discovery_model.u_software_name in software installation table, and then i need to groupby installed on at that point there will be count for each discovery model ryt. . That records count i need to store in my custom table field used count. The matching is done between tables by the discovery_model.u_software_name in the software installation and u_name field in custom table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2024 10:26 PM
@Tai Vu its not ,considering grouby installed on....every used count is updating as 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2024 01:25 AM
Hi @Sharath807
You can update the script to the below :-
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 = parseInt(count.getAggregate("COUNT"), 10);
totalCount += groupCount; // Add this count to the total
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 01:46 AM
Hi @Ravi Gaurav not working, displaying actual count. I need to display groupby count
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2024 02:16 AM
Try the below :-
var totalCount = 0;
var count = new GlideAggregate('cmdb_sam_sw_install');
count.addEncodedQuery("discovery_model.u_software_name=c421a3e387e4d21075920d460cbb350b");
count.groupBy('installed_on'); // Grouping by 'installed_on'
count.query();
while (count.next()) {
totalCount++; // Increment the total count for each group
gs.info("Installed on: " + count.getValue('installed_on')); // Display the value of 'installed_on' for each group
}
gs.info("Total group count: " + totalCount); // Display the total number of groups