The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

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

Dong Nguyen
February 23, 2014

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Henning Tietgens
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 Champions.
February 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.

TAGS
AUG Leaders

Atlassian Community Events