Calculating a default value for a date variable

arwalker
Kilo Contributor

I have a date variable field labeled 'start date' and I have another date field labeled 'expiration date'. What I am trying to do in a client script is default the expiration date 90 days from the start date. Also prevent end users from changing the expiration date beyond the 90 days. However they can change it to an earlier time. So (1) first thing is how to default the expiration date to 90 days from the start date and (2) prevent users from changing the expiration beyond the 90 days allowed.

7 REPLIES 7

Community Alums
Not applicable

Did you figure this out? I'm pretty new to this and trying to put a requested by date a few days out. I tried putting this in as the default value for the date/time variable, but it doesn't work.

gs.now().getNumericValue() + 86400000


valerie_gallot
Giga Expert

Did you try that :
javascript:gs.nowDateTime()+ 86400000;

(default value field can also contain a hard-coded value, like a static string or somethign like that; If you need to call a method, you have to indicate the javascript prefix)


sgrison
Tera Guru

set the default value on the variable to javascript:gs.daysAgo(-5) this will set the date 5 days in the future.


Community Alums
Not applicable

Both of these options seem to give completely random results. Every time you load the form, the default date is something completely different...sometimes a few hours in advance...sometimes months.

This script seems to work...from michael.baker in Default value + 2 weeks for date variable:
[quote]Your results are due to your user date format set differently than the system date format. Try the below code in the default value instead.


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