It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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 votes
Nic Brough Community Leader Oct 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.

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 Community Leader Oct 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.

Hi Thanos,

I use Search Template "Number range searcher". 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

1,099 views 7 0
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you