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

Michael Lorincz
Kilo Expert

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).

find_real_file.png

There shouldn't be a problem with the dates. The log statement is returning the following:

find_real_file.png

Any ideas? Your responses would be greatly appreciated. Thank you!

4 REPLIES 4

Mike Patel
Tera Sage

change

var date = gs.nowDateTime()

to

var date = new GlideDateTime();

Tanushree Doiph
Mega Guru

Hi, 

Hope below link will helps you,

https://community.servicenow.com/community?id=community_question&sys_id=28764fe1db1cdbc01dcaf3231f96...

 

Please mark correct and helpful as per your impact.

 

Thanks

Tanushree

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

asifnoor
Kilo Patron

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