Time spent in In progress + Open statuses -HOW TO?

Rumceisz October 29, 2012

Hi All,

I have a problem: I need to get the time spent in In progress + Open statuses for each issue.

I made a script (scripted field) but it fails. Can you please help?

import com.atlassian.core.util.DateUtils
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.history.ChangeItemBean
 
def componentManager = ComponentManager.getInstance()
def changeHistoryManager = componentManager.getChangeHistoryManager()
 
def inProgressName = "In progress"
def onHoldName = "Open"
def rt = [0]

//
// Loops through every status change
//
changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {ChangeItemBean statusChange ->
 
   // Get the time passed since status change
   def timeDiff = System.currentTimeMillis() - statusChange.created.getTime()
   // If the status change left our status, we want to subtract the time passed since then
   if (statusChange.fromString == inProgressName) { rt << -timeDiff }
   if (statusChange.fromString == onHoldName) { rt << -timeDiff }
   // If the status change goes to our status, we want to add the time passed since then
   if (statusChange.toString == inProgressName) { rt << timeDiff }
   if (statusChange.toString == onHoldName) { rt << timeDiff }
}
 
// 
// Now compute the sum of all array elements.
// Devide by 1000 to not show anything less than 60 seconds

4 answers

1 accepted

0 votes
Answer accepted
Mizan
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.
October 29, 2012

Try the below code . I have not tested it but modified the existing code which i found in the script runner docs. Hope it helps

import com.atlassian.core.util.DateUtils
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.history.ChangeItemBean
 
def componentManager = ComponentManager.getInstance()
def changeHistoryManager = componentManager.getChangeHistoryManager()
 
def inProgressName = "In Progress"
 
def rt = [0]
changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {ChangeItemBean item ->
 
    def timeDiff = System.currentTimeMillis() - item.created.getTime()
    if (item.fromString == inProgressName) {
        rt << -timeDiff
    }
    if (item.toString == inProgressName){
        rt << timeDiff
    }
}
 

def inOpen = "Open"
 
def rt1 = [0]
changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {ChangeItemBean item ->
 
    def timeDiff1 = System.currentTimeMillis() - item.created.getTime()
    if (item.fromString == inOpen) {
        rt1 << -timeDiff1
    }
    if (item.toString == inOpen){
        rt1 << timeDiff1
    }
}
 
DateUtils.getDurationString(Math.round(rt1.sum() / 1000)+Math.round(rt.sum() / 1000))

Rumceisz October 29, 2012

Hi Mizan,

I tested but it failed:

javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: Open for class: Script21 A stacktrace has been logged.

Thanks for help!

Rumi

Mizan
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.
October 30, 2012

Hi Rumi ,

I have edited the above code you can try it now.

Rumceisz October 30, 2012

Hi Mizan,

I tested your code and I get:

javax.script.ScriptException: java.lang.NumberFormatException: For input string: "9m" A stacktrace has been logged.

It seems to me that the code sums the 'In progress' time spent but exclude the Open status. And the result ("9m") is in the warning message not in the proper custom field.

Mizan
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.
October 31, 2012

I have edited the above script , i am not sure i think this wont give proper results ..

How about adding 2 scripted feilds (hide these 2 using behaviours plugin) one for Inprogress time and other for Open time and a 3rd field which will display the sum of these custom fields .

Chava Pemberton June 2, 2016

Did this ever work out?

I'm having the same problem with Open status

1 vote
Tansu Akdeniz December 23, 2013

Hi,

There is a Time in Status Plugin on marketplace. You can get reports depending on user, project and advanced mode. You can export the reports to excel also.

Tansu Akdeniz

0 votes
ROBERT FELICIANO August 23, 2021

Such a simple thing and Jira cannot do it? Really? After all these years adding features? Incredible.

0 votes
Andrey Markelov
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.
August 29, 2013

Suggest an answer

Log in or Sign up to answer