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

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

172 views 0 4
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