Put Yesterday's Date in query - gs.daysAgoStart(1) not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2012 12:50 PM
Hi All,
I have a requirement where I need to fetch records updated yesterday. I tried using gs.daysAgoStart(1) and gs.daysAgoEnd(1) but it seems they're not responding. I inferred it because when I comment those 2 filters the job runs fine and gets the record with other filters. I also tried using 'encoded query' (commented statement), but still no luck.
I have also tried using gs.beginningOfYesterday() but result was still the same.
This is actually a code snippet from "Scheduled Batch Job", just so that you know where the script is running.
--------------Script Snippet Start---------------------
sysAuditGR = new GlideRecord('sys_audit');
sysAuditGR.addQuery('sys_created_on','>=',gs.daysAgoStart(1));
sysAuditGR.addQuery('sys_created_on','<=',gs.daysAgoEnd(1));
sysAuditGR.addQuery('fieldname','hardware_status');
sysAuditGR.addQuery('tablename','IN',cmdbTablesList);
//sysAuditGR.addEncodedQuery('GOTOfieldname=hardware_status^tablename!=cmdb_ci_computer^ORtablename=NULL^sys_created_onONYesterday@javascript:gs.daysAgoStart(1)@javascript:gs.daysAgoEnd(1)');
sysAuditGR.query();
--------------Script Snippet End---------------------
Any help is highly appreciated. Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2012 12:00 PM
Try this:
sysAuditGR = new GlideRecord('sys_audit');
sysAuditGR.addQuery('fieldname','hardware_status');
sysAuditGR.addQuery('tablename','IN',cmdbTablesList);
sysAuditGR.addEncodedQuery("sys_created_onONYesterday@javascript:gs.daysAgoStart(1)@javascript:gs.daysAgoEnd(1)");
sysAuditGR.query();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2012 02:20 PM
Hi Shane,
Thanks for replying to my query. I did try your code. It didn't work either.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-23-2012 06:22 AM
Hi Sumukh,
What did that query return? Did it return too many/few results?
Also, I know table rotation is turned on for sys_audit - http://wiki.service-now.com/index.php?title=Table_Extension
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2015 05:28 AM
Hi Shane
Thank you for your response on this post, its fixed an issue with the same problem I have been trying to fix for over a day!
Thnaks again It did work on my instance