Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Print Active and incative incident with get rowcount

ARAVIND22
Tera Contributor

Hello Guys,

 

 Can you help me to print below use case in gliderecord:

 

 Print Active and incative incident with get rowcount

 

 

Regards,

Aravind

5 REPLIES 5

SuhasPSalunkhe
Kilo Guru
//Active Incident
var arrInc = [];
var grInc = new GlideRecord("incident");
grInc.addActiveQuery(); //use this to return active incidents
grInc.query();
gs.info('Total Active Incident : '+grInc.getRowCount());
while (grInc.next()) {
arrInc.push(grInc.getValue("number"));
}

gs.info(arrInc);

//Inactive incident
var arrInc = [];
var grInc = new GlideRecord("incident");
grInc.addInactiveQuery(); //use this to return active incidents
grInc.query();
gs.info('Total InActive Incident : '+grInc.getRowCount());
while (grInc.next()) {
arrInc.push(grInc.getValue("number"));
}

gs.info(arrInc);

Bhai I need to print both in a single script not seperate

SuhasPSalunkhe
Kilo Guru
var arrInc = [];
var grInc = new GlideRecord("incident");
//use this to return active incidents
grInc.query();
var vactive = 0;
var vinActive = 0;
var arrActive = [];
var arrInActive = [];
while (grInc.next()) {
if ( grInc.getValue('active') == true ) {
arrActive.push(grInc.getValue("number"));
vactive = vactive  + 1;
} else {
arrInActive.push(grInc.getValue("number"));
vinActive = vinActive + 1;
}

}

gs.print('ACTIVE INCIDENT COUNT : '+ vactive);
gs.print('ACTIVE INCIDENTS : '+ arrActive);
gs.print('INACTIVE INCIDENT COUNT : '+ vinActive);
gs.print('INACTIVE INCIDNET : '+ arrInActive);

1. You cannot use getrowcount here.

2. Either you can use GlideAggregate and Group by

jaheerhattiwale
Mega Sage

@ARAVIND22 You can use GlideAggregate to achieve this as below

 

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

while(incGa.next()){
    gs.info(incGa.active+" Incident count "+incGa.getAggregate("COUNT"));
}
 
Result:
jaheerhattiwale_0-1671084204736.png

 

Please mark as correct answer if this solves your issue.
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023