How to writ script JQL function to count the number of status?

Dear all,

I would like to search all the issues based on the number that those issues move to 1 specific status. (For ex, count the number of "re-open" time of 1 issue).

Currently, I add 1 Scritp Field and add the below script

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.history.ChangeItemBean
def componentManager = ComponentManager.getInstance()
def changeHistoryManager = componentManager.getChangeHistoryManager()
def reopenedName = "Reopened"
def countOpen = 0.0
changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {ChangeItemBean item ->
    if (item.toString == reopenedName){
        countOpen = countOpen + 1
    }
}
return countOpen as Double

It worked well but I'm wondering about the performance because this scirpt will run in each issues that we scanned.

I found that script JQL Function is another solution but when I start to write new function, I don't really understand how funciton operation? If possible, can you please support us or guide us the structure of 1 script JQL function.

Best Regards,

1 answer

0 vote
Henning Tietgens Community Champion Feb 23, 2014

I think, if you want to reduce the performance impact you have to write the counter while it's happening, so you have to create a number custom field and increase this field while the transition happens. Maybe you could run a script to do a one time calculation after you added the new custom field and the postfunction to increase the field. Than all fields should represent the current number.

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
Published Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

708 views 6 13
Read article

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