PRINT INCIDENT CATEGORY HARDWARE & SOFTWARE WITH TOTAL COUNT IN GLIDERECORD
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 07:28 PM
PLEASE HELP ME WITH THE BKOW SCRIPT TO GET THE TOTAL OF OF HARWARE AND SOFTWARE WITH LIST
var gr = new GlideRecord('incident');
gr.addQuery('category', 'software');
gr.addQuery('category', 'Hardware');
gr.query();
while(gr.next()){
OUTPUT NEEDED:
TOTAL NUMBER OF INCIDENT WITH HARDWARE CATEGORY IS - 10
TOTAL NUMBER OF INCIDENT WITH SOFTWARE CATEGORY IS - 12
Total number of incident is - 100
total number of incident with hardware and software is - 22
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 08:37 PM - edited 12-14-2022 08:37 PM
Hi @ARAVIND22 ,
Please try below code:-
var category1="software";
var category2="hardware"
var countSoftware=inc(category1);
var countHardware=inc(category2);
var totalCount=countSoftware+countHardware;
gs.print("Total number of incident: "+totalCount)
function inc(category)
{
var gr = new GlideRecord('incident');
gr.addQuery('category',category);
gr.query();
if(category=="software")
{
gs.print("TOTAL NUMBER OF INCIDENT WITH HARDWARE CATEGORY IS: "+gr.getRowCount())
return gr.getRowCount();
}
else if(category=="hardware")
{
gs.print("TOTAL NUMBER OF INCIDENT WITH HARDWARE CATEGORY IS: "+gr.getRowCount())
return gr.getRowCount();
}
}
I hope this helps
Please mark my answer correct if this helps you
Thanks
Mohit

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 08:37 PM
//----------------------- FOR ALL SOFTWARE
var ga = new GlideAggregate('incident');
ga.addAggregate('COUNT');
ga.addQuery('category', 'software');
ga.addQuery('active', 'true');
ga.query();
while (ga.next()){
gs.print('SOFTWARE' + '-->' +ga.getAggregate('COUNT'));
}
//--------------- FOR ALL HARDWARE
var ga = new GlideAggregate('incident');
ga.addAggregate('COUNT');
ga.addQuery('category', 'hardware');
ga.addQuery('active', 'true');
ga.query();
while (ga.next()){
gs.print('HARDWARE' + '-->' +ga.getAggregate('COUNT'));
}
//--------------- FOR ALL CATEGORY
var ga = new GlideAggregate('incident');
ga.addAggregate('COUNT');
ga.groupBy('category');
ga.query();
while (ga.next()){
gs.print(ga.getDisplayValue('category') + '|' + ga.getAggregate('COUNT'));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 10:14 PM - edited 12-14-2022 10:20 PM
@ARAVIND22 You can achieve it using GlideAggregate as below:
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 02:39 AM
@ARAVIND22 Can you please mark this as correct answer if this has solved your issue
ServiceNow Community Rising Star, Class of 2023

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 03:13 AM
Hi Arvind,
You can use below script without using encodedQuery
//var encodedQuery ="active=true^category=software^ORcategory=hardware";
var count = 0;
var softCount = 0;
var hardCount = 0;
var gr = new GlideRecord('incident');
//gr.addEncodedQuery(encodedQuery);
gr.addQuery('active',true);
gr.query();
while(gr.next()){
count++;
if(gr.category == 'software'){
softCount++;
}
if(gr.category == 'hardware'){
hardCount++;
}
}
var Total = parseInt(softCount) + parseInt(hardCount);
gs.print("TOTAL NUMBER OF INCIDENT WITH SOFTWARE CATEGORY IS : " +softCount);
gs.print("TOTAL NUMBER OF INCIDENT WITH HARDWARE CATEGORY IS : " +hardCount);
gs.print("Total number of incident is : " +count);
gs.print("Total number of incident with hardware and software is : " + Total);
Output :
[0:00:00.034] Script completed in scope global: script
Script execution history and recovery available here
*** Script: TOTAL NUMBER OF INCIDENT WITH SOFTWARE CATEGORY IS : 7
*** Script: TOTAL NUMBER OF INCIDENT WITH HARDWARE CATEGORY IS : 6
*** Script: Total number of incident is : 45
*** Script: Total number of incident with hardware and software is : 13
Kindly mark correct and helpful if applicable.