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."
}
Hello @Jake Jollimore
Please see this answer
https://community.atlassian.com/t5/Adaptavist-questions/Date-format-for-script-field/qaq-p/698130
Here you can set the custom format for displaying your date and also use the searcher "Date time range picker" so that you can query it in JQL based on your requirements.
So for the scripted field the template is custom but the searcher is "Date time range picker", searcher can be configured in the custom field configuration section.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Formats available here
And in the dateTimeFormatter you can use the custom style (Aug 20, 2018)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is great. Thank you! However, none of the options available in the dateTimeStyle link allow me to get the 'Aug 20, 2018' format I was hoping for. Is it possible to get a custom format?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can set the custom format using the method withStyle(String) in DateTimeFormatter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No matter what string I pass, eg:
$datePickerFormatter.withStyle('').format($value)
$datePickerFormatter.withStyle('MMM d, YYYY').format($value)
$datePickerFormatter.withStyle('mm:ss').format($value)
$datePickerFormatter.withStyle('dmy').format($value)
I keep getting the same output format:
28/Aug/18 12:19 PM
Any thoughts?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I also tried different formats but getting the date like 29/Aug/18 instead of excepted format.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.