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

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

Hi Orawan,

What Searcher and Template you use for your scripted field ?

0 vote

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.

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?

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.

Hi Thanos,

I use Search Template "Number range searcher". 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted yesterday in Confluence

Calling all marketing teams who use Confluence - we want to hear from you!

Hi Community! me again 🙂 If you’re a marketing team using Confluence, we want to hear your story! How did you start using Confluence? What are your use cases? What have been some of the benefits?...

83 views 2 3
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you