Is there a script field that could be configured to divide completed subtasks by total subtasks in one parent ticket? This would be used as a column in filter and dashboard results.
Hi Sarah,
Indeed, a scripted field seems to be the solution here. As for the code, assuming a completed subtask is one with a resolution, try this:
int totalSubTasks = issue.getSubTaskObjects().size()
int completedSubTasks = totalSubTasks.findAll{it.getResolution != null}.size()
int result = (completedSubTasks*100) / totalSubTasks
return result
Thanks Ivan! I attached a couple photos of two errors I received with that script. Any idea?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you stick to Java, you need to either convert or cast between variable types (e.g. use java.math.BigDecimal.intValue() to convert the value to an int) or use the right types (replace the "int" at the front of line 2 with BigDecimal)
If you flip to Groovy, you can use untyped variables - replace the three "int"s with "def". But you may need to cast the return value to the right type. i.e.
return (long) result
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this:
import com.atlassian.jira.issue.Issue
def totalSubTasks = issue.getSubTaskObjects().size()
def completedSubTasks = issue.getSubTaskObjects().findAll{(Issue) it.getResolution != null}.size()
def result = (completedSubTasks*100) / totalSubTasks
return (long) result
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.
you forgot to include an import:
import com.atlassian.jira.issue.Issue
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.
My mistake, forgot the parenthesis. It should be like this:
def completedSubTasks = issue.getSubTaskObjects().findAll{(Issue) it.getResolution() != null}.size()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks! This got rid of the any errors! When I preview a ticket that has several subtasks, of which some are closed, it returns null. Could this have to do with the Template selection? Attached is what the logs returned
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Indeed, you need to switch your field template to 'Number Field' and then create the field before you can use the preview function. Also make sure you set the searcher of this field (Administration -> Issues -> Custom fields -> Edit field) to 'Number Searcher'
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.
That error indicates that the script tried to calculate the percentage of completed subtasks in an issue where there are no subtasks at all. Let's add a check for that to the code:
import com.atlassian.jira.issue.Issue
def totalSubTasks = issue.getSubTaskObjects().size()
if (totalSubTasks > 0){
def completedSubTasks = issue.getSubTaskObjects().findAll{(Issue) it.getResolution() != null}.size()
def result = (completedSubTasks*100) / totalSubTasks
return (long) result
}
return null
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry for the delay,
Can you tell me if the field actually works? I mean if you ignore those errors, does it show you completed subtask percentage?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If all subtasks are open it shows 0 and if one subtask is closed and one is open, the field is null.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you post the whole error message, I can't see it on your screenshots.
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.
{ "customField": "Percentage of Subtasks Complete (com.atlassian.jira.issue.fields.ImmutableCustomField)", "issue": "PVP-52 (com.atlassian.jira.issue.IssueImpl)", "log": "org.apache.log4j.Logger@21c84325", "componentManager": "com.atlassian.jira.ComponentManager@13d2cfcc", "getCustomFieldValue": "groovy.lang.Closure", "enableCache": "groovy.lang.Closure" }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did this ever get resolved?! I am trying to do the same thing and I am getting the same error where if there is one open and one done it marks it as null but if all the subtasks are open then it shows 0
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Works for me with minor edits :
import com.atlassian.jira.issue.Issue
def totalSubTasks = issue.getSubTaskObjects().size()
if (totalSubTasks > 0){
def completedSubTasks = 0
for (subTask in issue.getSubTaskObjects()){
if (subTask.getResolution() != null){
completedSubTasks++
}
}
def result = (completedSubTasks*100) / totalSubTasks
return (long) result
}
return null
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How this script works if I need to exclude resoltution empty and resolution = 'Removed'?
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.