
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2020 05:21 AM
Hi guys, is it possible to query all records created on the month before last month?
Regards, Serhii
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2020 05:55 AM
Hi,
The filter condition shared by Dhananjay should work.
Reference below
Script also gives 16 count:
var gr=new GlideRecord('incident');
gr.addEncodedQuery('sys_created_on<javascript:gs.beginningOfLastMonth()^sys_created_on>javascript:gs.beginningOfLast60Days()');
gr.query();
gs.info(gr.getRowCount());
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2020 05:55 AM
Hi,
The filter condition shared by Dhananjay should work.
Reference below
Script also gives 16 count:
var gr=new GlideRecord('incident');
gr.addEncodedQuery('sys_created_on<javascript:gs.beginningOfLastMonth()^sys_created_on>javascript:gs.beginningOfLast60Days()');
gr.query();
gs.info(gr.getRowCount());
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2020 05:39 AM
Hi,
var gr=new GlideRecord('table-name');
gr.addEncodedQuery('sys_created_on<javascript:gs.beginningOfLastMonth()^sys_created_on>javascript:gs.beginningOfLast60Days()');
gr.query();
while(gr.next()){
gs.addInfoMessage(gr.number);//Change to correct field or you can add your logic here.
}
Mark correct/helpful based on impact.
Thanks,
Dhananjay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2020 05:44 AM
Hi,
gr.addEncodedQuery('sys_created_on<javascript:gs.beginningOfLastMonth()^sys_created_on>javascript:gs.beginningOfLast60Days()');
lets say you are in July and you want May records then above query will do trick for you.
Thanks,
Dhananjay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2020 05:25 AM
Hi,
If this has resolved kindly mark this as correct so others will refer same in future and by marking this as correct question will remove from unanswered thread.
Thanks,
Dhananjay.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2020 07:59 AM
Hi Serhii,
I believe the answer you have marked correct is already provided by me. I will appreciate if you mark my response as correct.
Thanks,
Dhananjay.