Can custom date fields be defaulted to a value relative from today?

Dave Thomas
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 30, 2011

I'd like to have a field called "Due Date" that has a default value of 10 days from the current day. Is this possible? I don't see a way to do this using traditional methods, but perhaps it can be achieved through some creative javascript?

3 answers

1 accepted

1 vote
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 30, 2011

Not natively, but you're spot on with the javascript suggestion.

Try

{code}

<script language="javascript" type="text/javascript">
<!--

var startChg = document.getElementById("customfield_10288");
if (startChg)
{
var today=new Date()
today.setDate(today.getDate()+7)
startChg.value=today
}
// -->

{code}

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 30, 2011

"Bother!", said Pooh as he realised he didn't know how to do a code box in "Answers"

Andrei [errno]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 30, 2011

@Nic - everybody votes! -> : https://jira.atlassian.com/browse/ANSWERS-57

Dave Thomas
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 30, 2011

Thanks Nic! I'll give this a shot (adding a check to see if the value is currently empty before setting the default, of course).

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 1, 2011

@Webwesen - Thanks! Voted

@circusdog - yes, sorry, I forgot, I was defaulting in a "create" screen. For edit, you should check the content first.

0 votes
huangbe December 17, 2014

Hi Nic Brough

  Thanks for your answer and Javascript.

  It has worked halfway for me. It does successfully fill in the date field. But the format is incorrect.

  As you may know, JIRA's date field is formatted "dd/MMM/yy h:mm a"

  But the new Date() gives it "DDD MMM DD YYYY hh:mm:ss timezone"

Eg: "Tue Dec 23 2014 15:15:23 GMT+1100 (AUS Eastern Daylight Time)"

 

  And to top it off, we can't manually update the date anymore.

 

  Does anyone know how to format the date correctly again?

0 votes
Chad Larkin August 5, 2011

You could also set up a post function using a groovy (or other) script that populates the dues date and add it to your workflow. While we did something similar to that with assigned date, though more complicated that what this would be. If you would like to see what we did you can read about it here.

Suggest an answer

Log in or Sign up to answer