- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2020 10:19 AM
Hello All, the aggregate count is not working as expected. Please help. The dot-walk addQuery should return a count of 100 for example, but I am getting 0 results.
var count = new GlideAggregate('alm_hardware');
count.addQuery('model.u_field','1111111');
count.addAggregate('COUNT');
count.query();
gs.log("This count is empty: "+count.getAggregate('COUNT'));
if(count.next()){
gs.log("This count is working: " +count.getAggregate('COUNT'));
gs.log('count');
}
Results:
*** Script: This count is empty: null
*** Script: This count is working: 0
*** Script: count
*** Script:
----------------------------------------------------------
The Second row should be a count of 100
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2020 12:21 PM
To help you, you can run this code:
var usedModels = 0;
var grModel = new GlideRecord('cmdb_model');
grModel.addQuery('u_field', '1111111');
grModel.query();
while (grModel.next()) {
var grHardware = new GlideRecord('alm_hardware');
grHardware.addQuery('model', grModel.getUniqueValue());
grHardware.query();
if (grHardware.next()) {
gs.log("The model: " + grModel.getDisplayValue() + " is used in Hardware");
usedModels++;
}
}
gs.log("There are: " + grModel.getRowCount() + ' Models available with 111111');
gs.log("There are: " + usedModels + ' Models used for Hardware with 111111');
Please share the log results.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2020 10:27 AM
Use below code
var count = new GlideAggregate('alm_hardware');
count.addAggregate('COUNT', 'model_category');
count.addQuery('model.u_field','1111111');
count.query();
gs.log("This count is empty: "+count.getAggregate('COUNT'));
if(count.next()){
gs.log("This count is working: " +count.getAggregate('COUNT'));
gs.log('count');
}
https://developer.servicenow.com/blog.do?p=/post/glideaggregate/
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2020 11:07 AM
Thank you, no improvement.
[0:00:00.042] Script completed in scope global: script
Script execution history and recovery available here
*** Script: This count is empty: null
*** Script:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2020 11:55 AM
What is the data type of u_field field?
If this is a reference field, then you need sys_id in addQuery() function.
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2020 02:29 PM
the u_field is a string field.