- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 12:23 PM
I would like to display a date 90 days from Today() on a form and use it in a variable in my catalog item.
I'm assuming an "On Load" client script but can't seem to get the syntax right.
Any assistance would be appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 05:44 AM
I figured this out. It turns out to be very simple.
I've seen other posts like mine so I'm showing the soluton were going to use.
Hopefully others can do this too.
Simply put in this Javascript as the "Default Value". That's it!
javascript:var gdt=new GlideDateTime();gdt.addDays(90);gdt.getDate();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2023 02:19 PM - edited 06-20-2023 02:24 PM
Hi, ServiceNow does not have a client API that manages date\time so your options are to manage this directly (including formatting) in the client script via native java-script date methods - this would result in a date\time based on user browser/Pc configuration and so may not be consistent.
Or create a server side script-include to utilize the SNC GlideDateTime methods, which you would call from the client script via GlideAjax
Edit:
Possibly something like this for a client side solution
var tmpDate = new Date();
tmpDate.setDate(tmpDate.getDate() + 90);
var myDate = tmpDate.getFullYear() + '-' + (tmpDate.getMonth() + 1) + '-' + tmpDate.getDate();
//g_form.addInfoMessage('tmpDate ' + tmpDate);
//g_form.addInfoMessage('myDate ' + myDate);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 04:41 AM
Hi @Joe Taylor
you can acheive this by GlideDateTime(); method.
var today_date = new GlideDateTime();
var future_date = today_date.addDaysUTC(90); //adding 90 days to today's date.
you can set future_date on the form variable.
Regards,
Ravi Chandra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 05:44 AM
I figured this out. It turns out to be very simple.
I've seen other posts like mine so I'm showing the soluton were going to use.
Hopefully others can do this too.
Simply put in this Javascript as the "Default Value". That's it!
javascript:var gdt=new GlideDateTime();gdt.addDays(90);gdt.getDate();