Forums

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

Time in "Open" Status

Drishti Maharaj
Contributor
August 10, 2022

Hi,

I have found the following code but I require some assistance to modify the code.

I wish to show the time that an issue is in the "Open" status but with the code, it is somehow adding the "Open" status and "In Progress" time together and not accurately showing the information.

How do I modify this to just show the "Open" time?

 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.history.ChangeItemBean;
import com.atlassian.jira.issue.Issue;
 
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
 
def statusName = "Open"
def createdDateDiff = System.currentTimeMillis() - issue.getCreated().getTime()
 
List<Long> rt = [0L]
 
rt << createdDateDiff
 
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")
changeItems.reverse().each {ChangeItemBean item -> item.fromString
 
 // Get the time passed since status change
 def timeDiff = System.currentTimeMillis() - item.created.getTime()
 
 // If the status change left our status, we want to subtract the time passed since then
 if (item.fromString == statusName) {
 rt << -timeDiff
 }
 
 // If the status change goes to our status, we want to add the time passed since then
 if (item.toString == statusName){
 rt << timeDiff
 }
}
 
def total = (rt.sum() as Long) / 1000
 
return Math.round(total) ?: 0
Thank you. 1.JPG

1 answer

1 accepted

0 votes
Answer accepted
Timothy
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.
October 8, 2014

Suggest an answer

Log in or Sign up to answer