Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Listener Script to sum up story points of resolved issues in an Epic

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)

1 answer

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()}")

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you