Total time this issue has been In Progress modification not working

Hello, I'm using the provided total time this issue has been In Progress groovy script.

I modified it so that it would tell me how long it was in it's initial "New" state. When I try and preview the answer, I get no answer whatsoever. The issue has been transitioned out of the status, and it was in that "New" status for about 5 days... any ideas?

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.issue.Issue
import com.atlassian.core.util.DateUtils
 
def componentManager = ComponentManager.getInstance()
def changeHistoryManager = componentManager.getChangeHistoryManager()
 
def inProgressName = "New"
 
def rt = [0]
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")
changeItems.reverse().each {ChangeItemBean item ->
    item.toString == inProgressName
 
    def timeDiff = System.currentTimeMillis() - item.created.getTime()
    if (item.fromString == inProgressName) {
        rt << -timeDiff
    }
    if (item.toString == inProgressName){
        rt << timeDiff
    }
}
 
if (! changeItems) {
    rt << (System.currentTimeMillis() - issue.getCreated().getTime())
 
}
 
// doesn't show anything if less than 60 seconds
DateUtils.getDurationString(Math.round(rt.sum() / 1000))

1 answer

1 accepted

0 votes
Answer accepted

Modified the script as such: 

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.issue.Issue
import com.atlassian.core.util.DateUtils

def componentManager = ComponentManager.getInstance()
def changeHistoryManager = componentManager.getChangeHistoryManager()

def inProgressName = "New"

def rt = [0]
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")
changeItems.reverse().each {ChangeItemBean item ->
item.toString == inProgressName

def timeDiff = System.currentTimeMillis() - item.created.getTime()
if (item.fromString == inProgressName) {
rt << -timeDiff
}
if (item.toString == inProgressName){
rt << timeDiff
}
}

if (! changeItems) {
rt << (System.currentTimeMillis() - issue.getCreated().getTime())

}
rt << (System.currentTimeMillis() - issue.getCreated().getTime()) 
double hours = rt.sum()/1000/60/60

Adding in the 

rt << (System.currentTimeMillis() - issue.getCreated().getTime())

at the end made the "New" state finally get calculated the right way. Also, to make the field queryable (although less pretty) I kept it in number form.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Wednesday in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page

                                                      &nbsp...

125 views 0 3
Read article

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