Defaulting a Date/Time field to 2 weeks from current Date/Time

jlaue
Kilo Sage

Hello -

We have a 'due date' field on one of our forms and we are looking to have that field default to 2 weeks from the Current Date/Time.   I was looking around for the best way to accomplish this.   I have not used Dynamic Default values in a field before, but I am wondering if this is the best place to do this.   Essentially the user will be clicking on a Create New Form link and I want the Due Date field on that form to default to 14 days from the current time that the form was opened.  

Thanks!!

1 ACCEPTED SOLUTION

Deepak Kumar5
Kilo Sage

Use below in default value.


javascript:var d = new GlideDateTime(); d.setValue(gs.daysAgo(-14)); d.getDisplayValue();


View solution in original post

4 REPLIES 4

Deepak Kumar5
Kilo Sage

Use below in default value.


javascript:var d = new GlideDateTime(); d.setValue(gs.daysAgo(-14)); d.getDisplayValue();


That did it!   Thank you!!


I took this answer and refreshed it so it's easier to ready.  ( I hate double negatives 😉)
Granted I only needed the date:

javascript:var d = new GlideDateTime(); d.addDays(14); d.getDate();


or if you need date/time

javascript:var d = new GlideDateTime(); d.addDays(14); d.getDisplayValue();

 
Validated in the Global scope, screen cap from sys_user table

bevo_0-1742400993232.png

 

Jenna
Tera Expert

Thank you Deepak. Is there a way to not allow prior dates from being selected? Make them read only?