Could you please provide me the script to find number of incidents opened this month
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2024 05:02 AM
Could you please provide me the script to find number of incidents opened this month
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2024 05:21 AM
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
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2024 05:24 AM - edited ‎03-01-2024 05:27 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2024 05:41 AM
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:
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-01-2024 06:37 AM
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/