- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2013 04:14 AM
Hi all,
I'm trying to produce an onChange client script to determine whether the date entered in the 'start_date' field on a Change_Request is before or after NEXT Thursday (relative to NOW).
I've been looking at the guidance here: http://wiki.servicenow.com/index.php?title=GlideDateTime#GlideDateTime.28.29 but I'm struggling to see how I can create a GlideDateTime object and set it to the newValue of the 'start_date' field. But I may be heading in the wrong direction with this... Any advice appreciated.
Regards
Jamsta.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-06-2018 01:22 PM
For those not looking at current date and instead looking at a date field, I learned that you can use the getDayOfWeek Glide function to check against the current record (so you can use it in a business rule, or, in our case, a workflow). My script below checks to see if a start or end date/time for a change record is between Friday and Sunday, returning True (and sending the change for added review) if that is the case:
answer = isWeekend();
function isWeekend() {
var impstart = current.start_date.getGlideObject().getDayOfWeek();
var impend = current.end_date.getGlideObject().getDayOfWeek();
if (impstart >= 5 || impend >= 5) {
return 'yes';
}
return 'no';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2013 07:34 AM
To do that type of date processing you'll be relying more on JavaScript than you will on ServiceNow.
See http://stackoverflow.com/questions/3638906/get-date-of-specific-day-of-the-week-in-javascript .
There are actually many sample scripts on Google that show how to calculate the date of a day of next week. Once you get that, you can do your time comparisons by comparing the date of next week and the one they chose.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2013 02:37 PM
Thank you for the pointer Aaron. Looks like I'll be able to do what I'm after with that code.
Regards
Jamsta.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2013 04:23 PM
Actually, one more thing... on the same issue. What's the best way to convert a date retrieved by g_form.getValue('start_date') into an actual javascript date object? I've been playing around with
var date1=Date.parse(exampleDate);
but I've discovered this works in Chrome and IE but not in Firefox. Is there a tried and tested way of doing this in a common way for all browsers?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-08-2013 08:53 AM
Hi again.
For this I typically take the opposite route and convert the JavaScript time to ServiceNow's formatting. There are a couple examples on http://stackoverflow.com/questions/3066586/get-string-in-yyyymmdd-format-from-js-date-object
There are a ton of samples if you search Google for "javascript date yyyy-mm-dd" as there's amillion different ways it can be done in JavaScript. My favorite is in the link I provided though.
I hope this helps!