
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2016 09:48 AM
I have a variable that is a date field. I want the date field to be 5 days out from the date the request was opened?
I've reviewed a SN Wiki article for Date/Time scripts, but after extensive reading of that article it didn't seem like any of the solutions worked so just trying to get some assistance.
Thanks,
Karen
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2016 10:55 AM
Karen,
The script should be:
var today = new Date();
var dateMS = today.getTime();
dateMS = dateMS + (5*24*60*60*1000);
var newDT = new Date();
newDT.setTime(dateMS);
g_form.setValue('ftr_needed_by',formatDate(newDT,g_user_date_format));

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2016 09:54 AM
Hi Karen,
Hope below link helps
Scoped GlideDateTime API Reference - ServiceNow Wiki
Check specifcially 4.35 addDaysLocalTime(Number amount) in above link
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2016 09:58 AM
go to your variable. Under the default tab add something like
javascript:
u_my_date_field = gs.daysAgo(-4) //where u_my_date_field is the name of the date field you are trying to populate.
In the Wiki go here to find out more: GlideSystem Date and Time Functions - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2016 11:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2016 10:00 AM
Hi,
You can do this:
var gdt = new GlideDateTime(current.opened_at);
gdt.addDaysUTC(5);
gs.print(gdt.getDate());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2016 11:20 AM
Thank you for your input as well.
I enter this a default value inside the variable and the date shows up as the current day's date.
Not really sure what is going on.