Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Need to create a duration calculated scripted field.

sai siva March 28, 2022

Hi i need to calculate the time the issues is in specific issue type using a scripted field.

  1. when the issue is moved to a bug the field should calculate the time .
  2. when the same issue is moved to another issue type story the calculation should be stopped.
  3. when the issue is back to the bug issue type the calculation should be started again.\

any suggestion regarding this ?

1 answer

1 vote
Anzar
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 21, 2022

Hi,

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

def inProgressName = "Bug"

List<Long> rt = [0L]
def changeItems = changeHistoryManager.getChangeItemsForField(issue, "issuetype")
changeItems.reverse().each {ChangeItemBean item ->
def timeDiff = System.currentTimeMillis() - item.created.getTime()
if (item.fromString == inProgressName) {
rt << -timeDiff
}
if (item.toString == inProgressName){
rt << timeDiff
}
}

def total = rt.sum() as Long
return (total / 1000) as long ?: 0L


And let me know if that solves the issue, please share the answer if already been resolved.

Regards,

Anzar

Suggest an answer

Log in or Sign up to answer