Scripted Field for Estimation Accuracy

O. Funkhouser May 15, 2013

I would like to a Scripted Custom Field to JIRA issues that adds the sum of remaining estimates with the sum of time spent so far (this includes the current issue and all sub-tasks). It seems that the Scripted Custom Field is the way to do this. Can anyone responde with script syntax that accomplishes this? Thanks.

2 answers

1 accepted

2 votes
Answer accepted
O. Funkhouser June 4, 2013
I figured it out.  For those interested, here is the code:

import com.atlassian.jira.ComponentManager

def timeWorked = issue.getTimeSpent()
if (timeWorked == null) timeWorked = 0

def timeEstimated = issue.getEstimate()
if (timeEstimated == null) timeEstimated = 0

def subTaskManager = ComponentManager.getInstance().getSubTaskManager();

Collection subTasks = subTaskManager.getSubTaskObjects(issue)

if (subTaskManager.subTasksEnabled && !subTasks.empty) {
    subTasks.each {
        if (it.getTimeSpent() != null) {
            timeWorked += it.getTimeSpent()
        }
       if (it.getEstimate() != null) {
            timeEstimated += it.getEstimate()
        }
    }
}

return (timeWorked + timeEstimated)/3600

 
0 votes
Corentin Méhat
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.
June 5, 2019

Following the deprecation of ComponentManager with JIRA 7.11, this works with ComponentAccessor (tested with JIRA 8.1.1 + ScriptRunner 5.5.6.1-jira8)

 

import com.atlassian.jira.component.ComponentAccessor

//in case "issue" is undefined in your context
//def issueManager = ComponentAccessor.getIssueManager()
//def issue = issueManager.getIssueByKeyIgnoreCase("PRJ-122")

def timeWorked = issue.getTimeSpent()?:0
def timeEstimated = issue.getEstimate()?:0


def subTaskManager = ComponentAccessor.getSubTaskManager();
Collection subTasks = subTaskManager.getSubTaskObjects(issue)
if (subTaskManager.subTasksEnabled && !subTasks.empty) {
subTasks.each {
timeWorked += it.getTimeSpent()?:0
timeEstimated += it.getEstimate()?:0
}
}

return (timeWorked + timeEstimated) / 3600

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events