I'm trying to create a scripted field on a parent task that gives me a percentage of the work completed based on the Time Spent and Remaining Estimate fields of the sub-tasks associated with that parent tasks. For example:
- Parent Task
- Sub-Task 1
- Sub-Task 2
- Sub-Task 3
The percentage of work completed in this case would be 83.3%. I want this number to appear on the parent task.
I've created a scripted field to calculate this, but I'm having issues pulling the information I want. Please note that I'm very new to coding in general, so I've built this by combining and toying with multiple examples I've found online. Here's what I have so far:
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Category
import com.atlassian.jira.config.SubTaskManager
SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager();
Collection subTasks = issue.getSubTasks()
Double timeSpentTotal = 0
Double remainingEstimate = 0
if (subTaskManager.subTasksEnabled && !subTasks.empty) {
subTasks.each {
timeSpentTotal += it.getTimeSpent()
// used .getTimeSpent because issue.getTimeSpent() works to retrieve Logged hours, but doesn't seem to work for subtasks
remainingEstimate += it.estimate
// used .estimate because issue.estimate works to retrieve the remaining estimate, but doesn't seem to work for subtasks
}
}
Double progress = ( timeSpentTotal / ( timeSpentTotal + remainingEstimate ) ) * 100
return progressWhenever I preview this using Script Runner, I get these errors: [GenericEntity.get] "getTimeSpent" is not a field of Issue and [GenericEntity.get] "estimate" is not a field of Issue. How can I adjust my script to get what I'm looking for? Is there a better way to do this that isn't based on the above script?
Thanks in advance for your help!