Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting issues by script field does not work.

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

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 Champion
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
TAGS
atlassian, mindful member, mindful member badge, atlassian community, community kudos, community giveaway, atlassian swag, community values, empathy and kindness, badge challenge, atlassian learning, community engagement, swag giveaway

Earn a Badge, Win a Prize 🎁

Earning the Mindful Member badge proves you know how to lead with kindness, plus it enters you into a giveaway for exclusive Atlassian swag. Take the quiz, grab the badge, and comment on our announcement article to spread the good vibes!

Start here
AUG Leaders

Atlassian Community Events