Comparing sys_created_on date in a background script

Charles Hong
Mega Expert

Hello i am trying to run a background script and one of the condition is for 'sys_created_on" to be after a certain date while the other conditions are or conditions based on catalog names. However, when running this background script i see that the results are not within the parameters of the date condition. Would anyone know why the date condition of the script is not being executed correctly? Please note this is just the top portion of my script and not in its entirety but i believe the problem exist here. 

var gr = new GlideRecord('sc_req_item');
gr.addOrCondition('cat_item', "Pens, Pencils & Markers");
gr.addOrCondition('cat_item', "Printer Supplies");
gr.addOrCondition('cat_item', "Paper");
gr.addOrCondition('cat_item', "Miscellaneous");
gr.addOrCondition('cat_item', "Mailing & Envelopes");
gr.addOrCondition('cat_item', "Desk Accessories");
gr.addOrCondition('cat_item', "Calendars & Planners");
gr.addOrCondition('cat_item', "Basic Supplies");
gr.addOrCondition('cat_item', "Adhesives & Tape");
gr.addOrCondition('cat_item', "Binders & Folders");
gr.addOrCondition('cat_item', "Binders & Folders");
gr.addQuery('sys_created_on' > '2018-04-20 16:09:35');

gr.query();
while (gr.next()){

1 ACCEPTED SOLUTION

Tony DiRienzo
Giga Guru

You have not formatted your date query correctly.  Try this instead:

gr.addQuery('sys_created_on', '>', '2018-04-20 16:09:35');

See the documentation on addQuery() here for more info:

API: GlideRecord.addQuery()

View solution in original post

2 REPLIES 2

Tony DiRienzo
Giga Guru

You have not formatted your date query correctly.  Try this instead:

gr.addQuery('sys_created_on', '>', '2018-04-20 16:09:35');

See the documentation on addQuery() here for more info:

API: GlideRecord.addQuery()

Thank you!