I have an Initialize script in a behavior where I am trying to copy a date field value to another date field value if the destination one is empty.
The copying aspect works but I wanted to format the date and followed the info here:
https://community.atlassian.com/t5/Jira-questions/Copy-date-field-if-date-field-is-null/qaq-p/10671
but when it runs it keeps setting the destination value to current date/time instead of the value from the other field.
Here is my code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.datetime.DateTimeFormatterFactory
import com.atlassian.jira.datetime.DateTimeStyle
if (getDestinationStepName() == "Scheduled")
{
def rcDateField = getFieldByName("Requested completion date")
def rcDateValue = rcDateField.getValue()
def scDateField = getFieldByName("Scheduled completion date")
def scDateValue = scDateField.getValue()
def dateTimeFormatterFactory = ComponentAccessor.getComponentOfType(DateTimeFormatterFactory)
def formatter = dateTimeFormatterFactory.formatter().withStyle(DateTimeStyle.DATE_TIME_PICKER)
def formatteddate = formatter.format(rcDateValue)
if (!scDateValue)
{
scDateField.setFormValue(formatteddate)
}
}
I've commented out the IF at the end so it's not that value isn't getting set, the value of formatteddate just isn't the formatted value of rcDateValue and is instead the current date/time.
Thanks.