- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2024 01:44 PM
Hello everyone!
I have been working on a solution to this problem for a while, but have not been able to do it successfully.
I am trying to load the number of incidents with the category hardware that exist when I load the Incident table in ServiceNow.
I have attached the image of my script include below.
Do I need a UI policy from here? I don't think a client script will work in this case as I want the count to appear in a pop-up when the Incident table loads.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2024 03:03 PM - edited 01-12-2024 03:04 PM
Why not use a display business rule. Check below:
var gaIncident = new GlideAggregate('incident');
gaIncident.addQuery('category', 'hardware');
gaIncident.addAggregate('COUNT');
gaIncident.query();
if (gaIncident.next()) {
var count = gaIncident.getAggregate('COUNT');
gs.addErrorMessage('Number of incidents with category hardware: ' + count);
gs.addInfoMessage('Number of incidents with category hardware: ' + count);
}
You can modify the message type you want to show, and it will display whenever you open an incident record.
Please accept solution OR mark helpful.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2024 03:03 PM - edited 01-12-2024 03:04 PM
Why not use a display business rule. Check below:
var gaIncident = new GlideAggregate('incident');
gaIncident.addQuery('category', 'hardware');
gaIncident.addAggregate('COUNT');
gaIncident.query();
if (gaIncident.next()) {
var count = gaIncident.getAggregate('COUNT');
gs.addErrorMessage('Number of incidents with category hardware: ' + count);
gs.addInfoMessage('Number of incidents with category hardware: ' + count);
}
You can modify the message type you want to show, and it will display whenever you open an incident record.
Please accept solution OR mark helpful.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2024 12:19 PM
Thanks so much for you help! This really worked well for me, will be adding GlideAggregate to my developer toolbox!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2024 04:37 PM
@Philip Conforzi Please update your script as follows.
var gr = new GlideRecord('incident');
gr.addQuery('category','hardware');//Hardware is choice label whereas hardware is value
gr.query();
return gr.getRowCount();
Also, instead of GlideRecord, GlideAggregate is more efficient to use for COUNT, SUM, MAX etc.