how i get the count of incidents which are created last month not in last 30 days with out specifying any date using background script

suprakash
Giga Expert

how i get the count of incidents which are created last month not in last 30 days with out specifying any date   using background script, without using any report types I dont want want to specify any date any month. suppose i am checking using background script in december   the count will display the no. of incidents for the month of november .... how can i do it??

1 ACCEPTED SOLUTION

drjohnchun
Tera Guru

Please try



var ga = new GlideAggregate('incident');
ga.addQuery('opened_atONLast month@javascript:gs.beginningOfLastMonth()@javascript:gs.endOfLastMonth()');
ga.addAggregate('COUNT');
ga.query();
var incidents_opened = ga.next() ? ga.getAggregate('COUNT') : 0;
gs.info(incidents_opened);



Please feel free to connect, follow, mark helpful / answer, like, endorse.


John Chun, PhD PMP see John's LinkedIn profile

visit snowaid


ServiceNow Advocate

View solution in original post

12 REPLIES 12

Chuck Tomasi
Tera Patron

Start by building the same query using the list filter and then copy the query to manipulate it the way you want.



See this video for help: Video: Scripting Complex Queries Quickly


Hi @Chuck Tomasi 

How do I get the count of incidents which were updated before 11 months ?

I guess list filter option would not be helpful in this.

How to check the count of incidents when we are selecting it from list in servicenow?

 

Community Alums
Not applicable

Suprakash,



You should be able to build a GlideRecord query that compares dates to today's date using these methods:



GlideSystem Date and Time Functions