ScriptRunner - Time in progress

We are trying to extract the Time in progress using the example on Adaptavist ScriptRunner documentation.

However, we are ending with a result of 83 years, 4 weeks, 1 day, 4 hours, 35 minutes for an item that was created 24 hours ago, while the result on "In progress" should be less than 24 hours.

According to my check the calculation is fine, it is just the output of the diff in milliseconds which is probably translated to date and then the gap is much larger.

I would appreciate if you can assist solving this issue.

import com.atlassian.core.util.DateUtils
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def inProgressName = "In progress"
List<Long> rt = [0L]
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")
changeItems.reverse().each {ChangeItemBean item ->
    item.toString == inProgressName
    //log.warn(System.currentTimeMillis())
    //log.warn(item.created.getTime())  
    //log.warn(System.currentTimeMillis() - item.created.getTime())
    
    def timeDiff = (System.currentTimeMillis()  - item.created.getTime())
    if (item.fromString == inProgressName) {
        rt << -timeDiff
    }
    if (item.toString == inProgressName){
        rt << timeDiff
        //log.warn(rt.sum())
    }
}
if (! changeItems) {
    rt << (System.currentTimeMillis() - issue.getCreated().getTime())
}
def total = rt.sum() as Long
//log.warn(rt)
return  total ?: 0L

 

 

1 answer

This widget could not be displayed.

I had the same problem. Try the following using "Text Field(multiline)" as template:

import com.atlassian.core.util.DateUtils
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean
 
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def inProgressName = "In Progress"
def rt = [0L]
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
    }
} 
DateUtils.getDurationString(Math.round(rt.sum() / 1000))

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

155 views 2 0
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