how to get count of total incidents in system logged

ganjimahesh
Tera Contributor

Total count of incident/SRs in system

8 REPLIES 8

Hi Mahesh,



The code would be as below:



var queryString="sys_class_name=incident^ORsys_class_name=sc_request";


var gr = GlideRecord('task');


gr.addEncodedQuery(queryString);


gr.query();


gs.log('Number of Incidents/Requests logged: ' + gr.getRowCount());



The query is based on the base task table, which Incident and Request tables extend from.   In the query condition, you can specify the table names (such as Incident and Request).



To confirm if this number is correct, you can type task.list in the Filter Navigator of your Application Menu, and manually build the filter from the GUI.



Hope this helps!



Thanks,


Jenny


Jeet
Tera Expert

Hi Brother,



Just search "Background" (script - background) on left navigation search.


Open it and Run below code :



1.


var gr = new GlideRecord("incident");


gr.query();


gs.log(gr.getRowCount());   // This will show in your system log




2.


var count = 0;


var gr = new GlideRecord("incident");


gr.encodedQuery("active=true"); // If you want all active and inactive incident remove this line


gr.query()


while(gr.next()){


count = count++


}



gs.log(count); // This will show in your system log




Thanks,


Jeet


HugoFirst
Kilo Sage

Hello Mahesh g,



It looks like you're getting lots of great advice and I have only one additional thought for you.


Do you archive old records?   If so, and if your requirement is to get the total number of incidents ever created,   you'll need to count the incidents in the archive table too.


One good proxy for the total number of incidents is the incident number itself.   If you started assigning them at 1 and incremented by 1, then the incident number of the most recent incident should be very close to the total number of incidents.   The discrepancy between the incident number and the actual total number of records would come from a "non-use case" where someone opens the incident form ( which is many cases assigns an incident number ) but does not actually submit the form.



I hope this helps.


Hari Babu
Mega Expert

Hi Friend ,

 

i have one query regarding the user table i have created the one user in the user table by the manually , but the user has added

 

ITIL role manually . how the role is added to him 

 

please give me the answer 

 

Regards,

Jagadeesh