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

This widget could not be displayed.

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 Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

509 views 3 18
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