Can someone validate my script (display of Release date with the Fix Version) ?

Aisha M
Contributor
June 20, 2018

Hello, I am using the below script for displaying the Release Date from the Fix version under the issue page. Currently, the field displays the DATE & TIME. I want to make sure ONLY the DATE gets displayed without the time. 

import java.sql.Timestamp
import java.text.DateFormat
import java.util.Date
Collection versions = issue.getFixVersions()
if (versions==null || versions.size()!=1)
return null
def version = versions.iterator().next()
new Date(version.releaseDate.time)

 

Can someone help me with how to remove the TIME from getting displayed ? Thank you

1 answer

1 accepted

0 votes
Answer accepted
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 20, 2018

Hello,

It should be like this:

import java.text.SimpleDateFormat

import java.sql.Timestamp
import java.text.DateFormat
import java.util.Date
Collection versions = issue.getFixVersions()
if (versions==null || versions.size()!=1)
return null
def version = versions.iterator().next()
SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MM-yyyy");

DATE_FORMAT.format(new Date(version.releaseDate.time);
Aisha M
Contributor
June 20, 2018

@Alexey Matveev Hi Alexey. Thank you for the response.

For the last line, getting the error pop up as 'unexpected token' and the script returns no value

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 20, 2018
import java.text.SimpleDateFormat

import java.sql.Timestamp
import java.text.DateFormat
import java.util.Date
Collection versions = issue.getFixVersions()
if (versions==null || versions.size()!=1)
return null
def version = versions.iterator().next()
SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MM-yyyy");

return DATE_FORMAT.format(new Date(version.releaseDate.time));
Aisha M
Contributor
June 20, 2018

@Alexey Matveev

Getting this error, 

Script Fields java.lang.Exception: The search indexer: class com.atlassian.jira.issue.customfields.searchers.DateTimeRangeSearcher expected your script to return a java.util.Date, but it returned an java.lang.String. We couldn't convert it to a java.util.Date

 

How to fix this ? Please help

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 20, 2018

The problem is that your searcher is com.atlassian.jira.issue.customfields.searchers.DateTimeRangeSearcher. You can change it to the free text. 

Also have a look at this thread

https://community.atlassian.com/t5/Adaptavist-questions/Date-format-for-script-field/qaq-p/698130

 

Aisha M
Contributor
June 21, 2018

@Alexey Matveev

The thread you shared was perfect ! Fixed it using the Custom template. Thank you so much.

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 21, 2018

You are welcome!

Suggest an answer

Log in or Sign up to answer