Glide date time add seconds not working

Lewis Hancox
Kilo Contributor

find_real_file.png

Hi ive posted above my code that currently works and creates announcements as needed the issue I am having is trying to add extra time to a variable based of gliddatetime time this is what I need to happen 

 

get glide date-time > add 12 hours > apply variable to 'to' field on the announcement 

 

I have tried following the ServiceNow documentation with the example in seconds pictured below

find_real_file.png

not only doesn't this add the extra time to the variable it also stops the script from running for some reason 

andy help is appreciated.

 

thank you in advanced 

1 ACCEPTED SOLUTION

The gdt() part is on line 7 is wrong. Just use gdt. So no ().

Line 6 would be nicer to code GlideDate() with in front of it new. It will work technically without, though using new makes it more clear:

gr.setValue('from', new GlideDate());

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

6 REPLIES 6

yeah, remove the brackets after the gdt, your adding the value as a variable, not a function call.:

gr.setValue('to', gdt);

Mark Roethof
Tera Patron
Tera Patron

Hi there,

This should work fine if you want to add 12 hours (= tested):

var gdt = new GlideDateTime();
gdt.addSeconds(43200);

So after this, you could use something like:

gr.to = gdt;

You are talking about inserting an announcement. Why doing .update()? Technically it will work, though would make it confusing if you look later at this script or somebody else has to do something with your script.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn