Sorting issues by script field does not work.

Владислав Яшин August 5, 2019

I created a script field to display the release date:

<-> import

Issue issue = issue
def fixVersions = issue.fixVersions

//return fixVersions
if (fixVersions) {
def releaseDates = fixVersions.findResults { it.releaseDate }.sort()
//return releaseDates
if (releaseDates) {
String data1 = releaseDates.last().format("dd/MM/yyyy")
DateFormat df1 = new SimpleDateFormat("dd/MM/yyyy")
Date data
data = df1.parse(data1)
return data
}
else {
Date date1 = new Date().parse("dd/MM/yyy", '01/01/9999')
return date1
}
}
else{
Date date1 = new Date().parse("dd/MM/yyy", '01/01/9999')
return date1
}

After reindexing, sorting works well until I change the release date for the release. And sorting doesn't work until I re-index. 

how to fix?

1 answer

1 accepted

1 vote
Answer accepted
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 5, 2019

Hello @Владислав Яшин 

Scripted fields, when they depend on data from outside then the index is not updated unless the issue on which the scripted field is present is modified. This is one of the short-coming of the script field and also explained in the docs

From the docs

It’s worth expanding a little on what I said above. You can only reliably use a calculated field to display a value that is based on the issue’s fields, or subtasks' fields, or linked issues. The reason why is because the value in the Lucene index is only updated when the issue is updated. If you compute some value based on data outside of the current issue, the value in the index may differ from the value displayed on the issue.

https://scriptrunner.adaptavist.com/latest/jira/scripted-fields.html

Владислав Яшин August 5, 2019

@Tarun Sapra , thanks

Suggest an answer

Log in or Sign up to answer