GlideDateTime() after() and compareTo() methods returning 'undefined'

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2020 09:05 AM
I've been attempting to utilize the GlideDateTime() methods of after() and compareTo() to determine whether one GlideDateTime object comes after the other. The only problem is that these methods seem to be returning 'undefined'. Here's the code I'm using (this is from a Script Include).
There shouldn't be a problem with the dates. The log statement is returning the following:
Any ideas? Your responses would be greatly appreciated. Thank you!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2020 09:15 AM
change
var date = gs.nowDateTime()
to
var date = new GlideDateTime();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2020 09:18 AM
Hi,
Hope below link will helps you,
Please mark correct and helpful as per your impact.
Thanks
Tanushree
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2020 10:17 AM
Hi,
compare() function requires object of GlideDateTime()
few corrections to your script; please update and test once
1) change line 126 from
var date = gs.nowDateTime();
to
var date = new GlideDateTime();
2) change line 139 as below
if(date.compareTo(new GlideDateTime(gr.u_end_date)) == 1)
comment line 137
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2020 12:27 PM
Hi,
You need to have GlideDateTime objects to use the glidedatetime functions.
Line 126
var date = new GlideDateTime();
Var 137
dueDate = new GlideDateTime(gr.u_end_date);
Similarly if you are checking anywhere else, make the changes accordingly.
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP