Want a date field to be 5 days out from the date the request was opened?

Cupcake
Mega Guru

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

1 ACCEPTED SOLUTION

manikorada
ServiceNow Employee
ServiceNow Employee

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


View solution in original post

19 REPLIES 19

manikorada
ServiceNow Employee
ServiceNow Employee

Karen,



Are you talking about Service Catalog variable or a normal field?


Sorry I forgot to specify a Service Catalog variable.


Mani I am thinking something like: var myDate=new Date(); myDate.now.format(myDate.setDate(myDate.getDate()+5),("dd/mm/yyyy");


manikorada
ServiceNow Employee
ServiceNow Employee

Karen,



Have a catalog client script such that :



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(<<variable_name>>,formatDate(newDT,g_user_date_format));