Adaptavist ScriptRunner for Jira Cloud - Sum up Story Points Script Listener

Created by Kristian Walker last modified
 * 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) {

// Retrieve all the subtasks of this issue's parent
def parentKey = issue.fields.parent.key
def allSubtasks = 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.
        .issues as List<Map>"Total subtasks for ${parentKey}: ${allSubtasks.size()}")

// Sum the estimates
def estimate = allSubtasks.collect { Map subtask ->
    subtask.fields.customfield_10036 ?: 0 // Update this line with the ID of the story points field for your instance.
}.sum()"Summed estimate: ${estimate}")

// Get the field ids
def fields = get('/rest/api/2/field')
        .body as List<Map>

// Note - The custom field specified here must be a number field as it returns a number type
def summedEstimateField = fields.find { == "Story Points" }.id // Update this Line with the name of your Custom Number field that will store the value on your parent issue."Custom field ID to update: ${summedEstimateField}")

// Now update the parent issue
def result = put("/rest/api/2/issue/${parentKey}")
        .header('Content-Type', 'application/json')
        fields: [
                (summedEstimateField): estimate

// check that updating the parent issue worked
assert result.status >= 200 && result.status < 300

Comments (0)


You can clone a snippet to your computer for local editing. Learn more.