The CreatorCon Call for Content is officially open! Get started here.

GlideDateTime method addSeconds() seems not to be working

dp11
Tera Guru

Hi,

I am trying to use the addSeconds() method in the following way:

var x = new GlideDateTime(current.due_date);
gs.log("x: " + x.getValue());

var y = new GlideDateTime(x);

gs.log("y: " + y.getValue());

var z = y.addSeconds(3600);

gs.log("z: " + z.getValue());

The values for x and y prints out fine. The value for z prints as 'undefined'. Please let me know if there is something wrong in it.

Thanks!

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Dp,

Try this and check below. the method addSeconds doesn't return anything so it is giving undefined

var x = new GlideDateTime(current.due_date);
gs.log("x: " + x.getValue());

var y = new GlideDateTime(x);

gs.log("y: " + y.getValue());

y.addSeconds(3600);

gs.log("z: " + y.getValue());

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

 

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

View solution in original post

6 REPLIES 6

SanjivMeher
Kilo Patron
Kilo Patron

Why not just this

 

var x = new GlideDateTime(current.due_date);
gs.log("x: " + x.getValue());

 x.addSeconds(3600);

gs.log("x: " + x.getValue());


Please mark this response as correct or helpful if it assisted you with your question.

Thanks Sanjiv! I overlooked the fact that addSeconds() did not return any value.