/* * This listener must be set to fire on the issue updated event and the field specified * to store the value must be on the issue screens * "All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner * license shall be granted a non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed or * amended and must be included in any circumstances where the code snippet is shared by You or a third party." */if(!issue.fields.issuetype.subtask){return}// Retrieve all the subtasks of this issue's parentdefparentKey=issue.fields.parent.keydefallSubtasks=get("/rest/api/2/search").queryString("jql","parent=${parentKey}").queryString("fields","parent,customfield_10036")// Update this line with the ID of the story points field for your instance..asObject(Map).body.issuesasList<Map>logger.info("Total subtasks for ${parentKey}: ${allSubtasks.size()}")// Sum the estimatesdefestimate=allSubtasks.collect{Mapsubtask->subtask.fields.customfield_10036?:0// Update this line with the ID of the story points field for your instance.}.sum()logger.info("Summed estimate: ${estimate}")// Get the field idsdeffields=get('/rest/api/2/field').asObject(List).bodyasList<Map>// Note - The custom field specified here must be a number field as it returns a number typedefsummedEstimateField=fields.find{it.name=="Story Points"}.id// Update this Line with the name of your Custom Number field that will store the value on your parent issue.logger.info("Custom field ID to update: ${summedEstimateField}")// Now update the parent issuedefresult=put("/rest/api/2/issue/${parentKey}").header('Content-Type','application/json').body([fields:[(summedEstimateField):estimate]]).asString()// check that updating the parent issue workedassertresult.status>=200&&result.status<300
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.