PRINT INCIDENT CATEGORY HARDWARE & SOFTWARE WITH TOTAL COUNT IN GLIDERECORD

ARAVIND22
Tera Contributor

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

11 REPLIES 11

Mohit_Gupta
Tera Guru

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

SuhasPSalunkhe
Kilo Guru
//----------------------- 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'));
}

jaheerhattiwale
Mega Sage

@ARAVIND22 You can achieve it using GlideAggregate as below:

var incGa = new GlideAggregate("incident");
incGa.addAggregate("COUNT");
incGa.groupBy("category");
incGa.query();

while(incGa.next()){
    if(incGa.category == "hardware" || incGa.category == "software"){
    gs.info(incGa.category.getDisplayValue()+" Incident count "+incGa.getAggregate("COUNT"));
    }
}
 
Result:
jaheerhattiwale_1-1671085223342.png

 

Please mark as correct answer if this solves your issue.

@ARAVIND22 Can you please mark this as correct answer if this has solved your issue

Chetan Mahajan
Mega Sage

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.