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

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

3 answers

1 accepted

0 votes
Mizan Community Champion Oct 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))

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 Community Champion Oct 30, 2012

Hi Rumi ,

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

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 Community Champion Oct 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 .

Did this ever work out?

I'm having the same problem with Open status

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

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,880 views 12 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot