We are Jira Cloud
We are using a Listener Script to sum up the Story Points of issues with an Epic. The listener runs against Create Issue and Update Issue. We would like to modify the code to sum up only those Story Points on issues within the Epic that have been resolved. Unfortunately, I am not a coder and do not know where/how to add the required JQL to find the resolved issues. The code we are using to sum all Story Points (open and resolved) is below. I've bolded the code I believe needs to be modified. Would someone be able to provide a snippet of code to sum just the resolved issues?
// Get the ID of the fields for Story Points and Epic Link
def storyPointsField = get("/rest/api/2/field").asObject(List).body.find {(it as Map).name == 'Story Points'}.id
def storyPointsResolvedField = get("/rest/api/2/field").asObject(List).body.find {(it as Map).name == 'Story Points Resolved'}.id
def epicLinkField = get("/rest/api/2/field").asObject(List).body.find {(it as Map).name == 'Epic Link'}.id
// Retrieve all the issues in this issues' Epic
def epicKey = issue.fields."${epicLinkField}"
def issuesInEpic = get("/rest/agile/1.0/epic/${epicKey}/issue")
.asObject(Map)
.body
.issues as List<Map>
logger.info("Total issues in Epic for ${epicKey}: ${issuesInEpic.size()}")
// Sum the estimates
def estimate = issuesInEpic.collect { Map issueInEpic ->
issueInEpic.fields."${storyPointsField}" ?: 0
}.sum()
logger.info("Summed estimate: ${estimate}")
// Now update the parent Epic
def result = put("/rest/api/2/issue/${epicKey}")
.queryString("overrideScreenSecurity", Boolean.TRUE)
.header('Content-Type', 'application/json')
.body([
fields: [
"${storyPointsRemainingField}": estimate,
]
])
.asString()
// check that updating the parent issue worked
assert result.status >= 200 && result.status < 300
In the end, I am looking to populate two fields on the Epic:
Story Points (represents all story points for all issues in the Epic)
Story Points Resolved (represents all story points for resolved issues in the Epic)
With some great help from Adaptavist support, I have modified my Listener script to use a JQL search for the resolved issues. Code snippet below for anyone else who may be looking for the same thing. Bolded lone is the JQL:
// Retrieve all the issues in this issues' Epic
def epicKey = issue.fields."${epicLinkField}"
def issuesInEpic = get("/rest/agile/1.0/epic/${epicKey}/issue")
.queryString('jql', 'Status = Done')
.asObject(Map)
.body
.issues as List<Map>
logger.info("Total issues in Epic for ${epicKey}: ${issuesInEpic.size()}")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.