Put Yesterday's Date in query - gs.daysAgoStart(1) not working

sumukh
Kilo Expert

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.

4 REPLIES 4

ShaneBrazeal
Tera Contributor

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();


Hi Shane,

Thanks for replying to my query. I did try your code. It didn't work either.

Thanks.


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


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