I'm using ScriptRunner to create custom Script Fields, and my most recent one is to display the date an issue was last assigned in the format 'Aug 20, 2018'. That field is called 'Date Assigned'
Currently, the field is set as a Text Field type, but I want to be able to use filters/functions on that field like 'Date Assigned <= 10d' in my reports.
However, when I change the field type to 'Date Time Picker' or 'Absolute Date Time', I always get the following output:
'$datePickerFormatter.format($value)' or 'Invalid Date'
What am I doing wrong? P.S. If keeping the format of 'Aug 20, 2018' is going to prohibit me from changing it to a Date type field, I can use a different format.
Here's the script:
import com.atlassian.jira.issue.*
import com.atlassian.core.util.DateUtils
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager();
List<ChangeItemBean> changeItems = changeHistoryManager.getChangeItemsForField(issue, "assignee") //Get assignee change history
Date assignedDate //This will contain the most recent assigned date, if one exists
if(changeItems != null && !changeItems.isEmpty()){
changeItems.each{ci ->
if(new Date(ci.getCreated().getTime()) > assignedDate){
assignedDate = new Date(ci.getCreated().getTime())
}
}
}
if(assignedDate != null){
assignedDate.format("MMM d, YYYY")
} else {
"This issue has yet to be assigned."
}