Could you please provide me the script to find number of incidents opened this month

kpkumar2k9
Tera Contributor

Could you please provide me the script to find number of incidents opened this month

4 REPLIES 4

dgarad
Giga Sage

Hi @kpkumar2k9 

Please refer below script.

var inc= new GlideRecord('incident');
inc.getEncodedQuery('opened_atONThis month@javascript:gs.beginningOfThisMonth()@javascript:gs.endOfThisMonth()');
inc.query();
while(inc.next()){
    gs.print("count"+inc.getRowCount());
}

Regards,

Dharmaraj

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

_Gaurav
Kilo Sage

Hi @kpkumar2k9 
Please use the below code to get the number of the incident opened this month.

 

var grIncident = new GlideRecord('incident');
grIncident.addEncodedQuery("opened_atONThis month@javascript;gs.beginningOfThisMonth()@javascript;gs.endOfThisMonth()");
grIncident.query();

gs.print(grIncident.getRowCount());

Please mark this as helpful and accept it as a solution if this works for you.
Thanks!

swathisarang98
Giga Sage
Giga Sage

Hi @kpkumar2k9 ,

 

You can try the below code in background script or in Fix script,

 

var ga = new GlideAggregate('incident');
ga.addQuery('sys_created_onONThis month@javascript:gs.beginningOfThisMonth()@javascript:gs.endOfThisMonth()');
ga.addAggregate('COUNT');
ga.query();
var incidents_opened = ga.next() ? ga.getAggregate('COUNT') : 0;
gs.info("Total number of incidents created on this month are :- " + incidents_opened);

 

Result:

swathisarang98_0-1709300482952.png

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

 

AndersBGS
Tera Patron
Tera Patron

Hi @kpkumar2k9 ,

 

Please provide some additional context to why you need a script? Incidents opened this month is basic condition in the condition builder used across ServiceNow.

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/