- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2019 01:14 AM
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
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2019 01:41 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2019 01:41 AM
yeah, remove the brackets after the gdt, your adding the value as a variable, not a function call.:
gr.setValue('to', gdt);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2019 01:39 AM
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