- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2015 05:46 AM
Hi,
I am having a scheduled job which runs every hour to check if any of the change task have start date & time <= current date & time.
I have used
var today = new GlideDateTime();
var curDate = today.getDate().getNumericValue();
But every time I run the job the curDate = 1433721600000 it is not changing.
Thanks
Uma
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2015 08:57 AM
The function getDate() returns only date but not time and hence you will get same value for every hour in a day. Try following
var today = new GlideDateTime();
var curDate = today.getNumericValue();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2015 05:59 AM
How many different days have you checked? Your "today" variable will store the time and date of when it was initialized, and does so in GMT. In other words, your getDate() method will always show the same date in GMT until the next day, if you re-initialize the variable via script, in which it will go up by the amount of milliseconds in 24 hours.
Also, I generally recommend getLocalDate() and getLocalTime() for the sake of getting the value you're expecting rather than GMT.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2015 07:34 AM
Hi Uma,
The easiest way will be to use GlideRecord on 'change_task' table and add an encoded query.
You just need to add the filters on the required table in the list view and copy that query and use it in the code.
For eg. 'active=true^sys_created_onRELATIVEGE@hour@ago@1' will get all active records created on or after 1 hour i.e. within last 1 hour. This way you don't need deal with the date and time functions and time zones.
For using encoded query in GlideRecord see-
Encoded Query Strings - ServiceNow Wiki
http://wiki.servicenow.com/index.php?title=GlideRecord#addEncodedQuery&gsc.tab=0
» GlideRecord Query Cheat Sheet
You can also use 'gs.dateDiff()'.
Check GlideSystem Date and Time Functions - ServiceNow Wiki for info and example.
Thanks,
Tanaji
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2015 08:57 AM
The function getDate() returns only date but not time and hence you will get same value for every hour in a day. Try following
var today = new GlideDateTime();
var curDate = today.getNumericValue();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2015 02:28 AM
Hi All,
Thank you for the reply.
Gurpreet's answer was more suitable for my requirement.
Thanks,
Uma