I'am looking for a solution where I could measure time in minutes between two specific statuses in a ticket:
specifically between new ticket is registered, and closed.
Is there any solution I could use to calculate this and have these result stored in a custom field?
I have tried with scriptrunner and code below, but unfourtanetly where there will be some other status set, measure is not calculating any longer.....(only for this one particular).
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean
// Status to be counted
final statusName = 'New'
def changeHistoryManager = ComponentAccessor.changeHistoryManager
def totalStatusTime = [0L]
// Every status change is checked
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")
changeItems.reverse().each { ChangeItemBean item ->
def timeDiff = System.currentTimeMillis() - item.created.time
// Subtract time if the "from" status is equal to the status to be checked and from and to statuses are different.
// This allows to count the time the issue is in the state for the first time
if (item.fromString == statusName && item.fromString != item.toString) {
totalStatusTime << -timeDiff
}
// Add time if the "to" status is equal to the status to be checked
if (item.toString == statusName) {
totalStatusTime << timeDiff
}
}
def total = totalStatusTime.sum() as Long
// Every time (added or subtracted) is summed and divided by 1000 to get seconds
(total / 1000) as long ?: 0L
Any solution or help highly appreciated. Thank you!!!!!