jira query time taken between 2 states

Koen Blondeel February 24, 2016
 

1 answer

0 votes
Vasiliy Zverev
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 Leaders.
February 24, 2016

Here is script for Script Field provided by ScriptRunner plugin from created and some specified status:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.changehistory.ChangeHistory
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.issue.history.ChangeItemBean

/**
 * Return time between two statuses
 */

//Issue issue = null;
long endStatusTime = 0;

String endStatusName = "Закрыт"

ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager();
for(ChangeHistory changeHistory: changeHistoryManager.getChangeHistories(issue))
    for(ChangeItemBean changeItemBean: changeHistory.getChangeItemBeans()) {
        if (changeItemBean.getField().equals("status")){

             if( changeItemBean.getToString().equals(endStatusName) ){
                endStatusTime = changeItemBean.getCreated().getTime()
            }
        }
    }

return  String.format("%.2f", (endStatusTime - issue.getCreated().getTime())/(1000*60*60*24))

Suggest an answer

Log in or Sign up to answer