The sorting has broken when using the script field (Script Runner)

Orawan Sittakom
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.
October 9, 2016

The sorting has broken when value in the script field is changed without editing a JIRA issue.

  • I created a script field and enable for Story type.
  • The script that I created, it is used for getting the number of Open Bugs that are being linked to that Story. 

import com.atlassian.jira.component.ComponentAccessor

def closeNames = ["Closed", "Resolved"]
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def issueLinks = issueLinkManager.getInwardLinks(issue.id)

def subElements = issueLinks.findAll {
it.getIssueLinkType().getName() == "Bug to Story"
}.findAll {
!(it.sourceObject.status.name in closeNames)
}.findAll {
it.sourceObject.issueTypeObject.name == "Bug"
}

return subElements.size() as Double

  • The result on the script field returns properly. 
    For example: I have 2 Stories, SPT-6 and SPT-23
         SPT-6 has 2 opened bugs (SPT-20 and SPT-53) -> The script field shows "2"
         SPT-23 has 3 opened bugs (SPT-21, SPT-57, SPT-74) -> The script field shows "3"
    The result shows correctly, including sorting by using ORDER BY ASC or DESC

  • When I close some bugs, e.g. SPT-21 and SPT-57, the script field still calculates correctly, it show "1", instead of "3" on Story SPT-23. But the sorting has broken, it's not updated until I edit any field in SPT-23 or re-indexing JIRA.  

Please help investigate, is this a bug or is there any solution to fix this problem?

Thank you in advance. Any question on my information above, please let me know.

 

Regards,

Orawan.

3 answers

0 votes
Orawan Sittakom
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.
October 10, 2016

Hi Thanos,

I use Search Template "Number range searcher". 

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 10, 2016

This is not technically correct in the background, but an easy way to think about scripted fields is that "they store their data in the index, so they only get updated when an issue is indexed".  The changes you are making to issues at the other end of the links do not trigger any indexing on the Story.

Sadly, for links, there's no way to fix this that I know of - changes to links don't fire events that could be caught and checked for changes that might need an indexing run against an issue.

Orawan Sittakom
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.
October 10, 2016

Hi Nic,

Thank you for this information T_T 

May I ask you, is it possible to have improvement regarding this case in new version of JIRA or ScriptRunner plug-in?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 11, 2016

An improvement here would need JIRA to support the firing of events for changes on links.  I'm not sure ScriptRunner could be made to handle anything without support from JIRA.

0 votes
Thanos Batagiannis _Adaptavist_
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.
October 10, 2016

Hi Orawan,

What Searcher and Template you use for your scripted field ?

Suggest an answer

Log in or Sign up to answer