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

Mani two things:


1) It is rendering this way on the form, and 2) i tried selecting any date in it allowed it so I don't think it is calculating correctly


find_real_file.png


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


That is what I have.


find_real_file.png


Please fix this from your code:




g_form.setValue('ftr_needed_by',formatDate(newDT,g_user_date_format)); in quotes


This was perfect. I forgot to include the quotes around my variable name.
Much appreciated Rahuljain and Mani