Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Date Type Script Field returning '$datePickerFormatter.format($value)'

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."


1 answer

1 accepted

1 vote
Answer accepted
Tarun Sapra Community Leader Aug 28, 2018

Hello @Jake Jollimore

Please see this answer

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.

Tarun Sapra Community Leader Aug 28, 2018

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. 

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?

Tarun Sapra Community Leader Aug 28, 2018

You can set the custom format using the method withStyle(String) in DateTimeFormatter

No matter what string I pass, eg:

$datePickerFormatter.withStyle('MMM d, YYYY').format($value)

I keep getting the same output format:

 28/Aug/18 12:19 PM

Any thoughts?

Tarun Sapra Community Leader Aug 29, 2018

I also tried different formats but getting the date like 29/Aug/18 instead of excepted format. 

Posted a new question HERE to try to figure out the formatting issue.

Suggest an answer

Log in or Sign up to answer

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you