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