Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Get first date that is set

Joe Harmon
Contributor
September 3, 2019

Is there a way with the jira misc custom fields to pull the first date off into a custom field?  Something like "Original Due Date"

1 answer

1 accepted

0 votes
Answer accepted
David Fischer
Community Champion
September 4, 2019

You mean the first (non-empty) value ever set on a field? There is no such built-in custom field type, but you can achieve the same with a Calculated (scripted) Date/time field with the following formula:

def duedateHistory = issue.getFieldHistory("duedate")
if (duedateHistory)
return new java.text.SimpleDateFormat("yyyy-MM-dd").parse(duedateHistory.first().from ?: duedateHistory.first().to)
return issue.get("duedate")
Joe Harmon
Contributor
September 4, 2019

Yeah the scenario I have is that I have a custom date field called "Goal Date" that is going to be set and changed from time to time.  I want to be able preserve the first non-empty value as another custom field called Original Due Date.  That way I can perform any calculations and evaluations on "Goal Date" but I also have the original due date that was set for reference.  Does the above do that?  Am I creating the goal date as the calculated date time field or the original due date?

David Fischer
Community Champion
September 4, 2019

The above does that but with the Due Date field. You need to replace "duedate" with your custom field's name ("Goal Date") or ID ("customfield_xxxxx" - you can figure out what it is from the "Issue Fields" help tab below the formula editor).

Joe Harmon
Contributor
September 4, 2019

Thank you.

Joe Harmon
Contributor
September 6, 2019

David, seems like it is almost working, but all of the dates are showing up a day before.  So if it was set to September 8, 2019, it is showing as September 7, 2019. Also, is it possible to not show the time and only the date?

Joe Harmon
Contributor
September 6, 2019

I figured out the date formatting so that it doesn't show the time.  Now the only thing I need to figure out is why it is showing the day before. 

David Fischer
Community Champion
September 6, 2019

The reason why it's showing the day before is because the calculated field is handling the value, during formatting, in the system time zone instead of your own time zone. This is a bug (https://innovalog.atlassian.net/browse/JMCF-316) and it will be fixed in the next version.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events