Calculate and Display a future date on Catalog Form

Joe Taylor
Giga Guru

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.

1 ACCEPTED SOLUTION

Joe Taylor
Giga Guru

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();

View solution in original post

3 REPLIES 3

Tony Chatfield1
Kilo Patron

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);



 

GlideAjax | ServiceNow Developers

GlideDateTime | ServiceNow Developers

Ravi Chandra_K
Kilo Patron
Kilo Patron

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

 

Joe Taylor
Giga Guru

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();