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.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.