// Get all Tasks with a due_date in the past
var gr = new GlideRecord('task');
gr.addQuery('due_date', '<', gs.nowNoTZ());
gr.query();
...
According to the ServiceNow wiki, the ServiceNow database stores dates "in the internal format, yyyy-MM-dd HH:mm:ss, and the system time zone, UTC by default." This means when performing a comparison, the both values should be in UTC.
Suppose there are the following Tasks
Number Due date
TASK001 9/6/2017 1:10:00pm CDT
TASK002 9/6/2017 1:50:00pm CDT
Further suppose that the above script is executed at 1:48:23pm CDT. Here are the comparisons that will be run in the database, using the correct gs.nowNoTZ() function.
TASK001 will be returned, since its comparison evaluates TRUE
2017-09-06 18:10:00 < 2017-09-06 18:48:23
TASK002 will NOT be returned, since its comparison evaluates FALSE
2017-09-06 18:50:00 < 2017-09-06 18:48:23
Using the incorrect gs.nowDateTime() function, the right-hand value evaluated would be 2017-09-06 13:48:23, and neither task would be returned. In effect, the person assigned to these tasks would be given additional hours to complete their work: the difference between the local timezone and UTC.
ReplyDeleteIam very impressive your site gives the best and the most interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new posts, once again hats off to you..
servicenow online training hyderabad