I'm using the ScriptRunner script for getting the Time in a particular status. I am able to get the times for all other statuses except the first status after the issue is opened, in this case Open. Here is the script I'm using:
=======================================
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean
// Status to be counted
final statusName = 'Open '
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
I'm trying to adjust the script so that I can get the time in the first status which at this point keeps returning a zero.
Any pointers on how to adjust it to get the duration of the first status the issue transitions into?