Times an issue was in each status

Use a ScriptRunner Scripted field to display how many times an issue was in each workflow status.

  • Template: Text Field
  • Search Template: None

Requirements

Jira Jira (7.5 - 7.13)

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean

import static com.onresolve.scriptrunner.canned.util.OutputFormatter.markupBuilder

Map statusMap = [:]
ComponentAccessor.changeHistoryManager.getChangeItemsForField(issue, "status").each { ChangeItemBean item ->
    if (statusMap[item.fromString]) {
        if (item.fromString != item.toString) {
            statusMap[item.fromString] ++
        }
    } else {
        statusMap[item.fromString] = 1
    }
}

if (statusMap) {
    markupBuilder {
        ul {
            statusMap.collect { status, times -> "$status : $times" }.each { status ->
                li(status)
            }
        }
    }
} else {
    null
}
Discovered an issue? Report it here

Suggested for you