Groovy script for getting sprints for a given issue Edited

Alex Christensen Community Champion May 23, 2017

For a given set of issues, I am trying to get the active sprint for each issue and determine if they are all the same sprint. How can I achieve this using a groovy script?

I'm probably just missing something in the javadoc, but I can't find anything that will allow me to get an issue's active sprint(s). What is the return type of the Sprint custom field type? I found this answer to be helpful to me, but it only pulls the data for the last sprint, not the current active one (if it exists).

This regards JIRA Softare 7.3.1, by the way.

1 answer

1 accepted

0 votes
Accepted answer
Alex Christensen Community Champion May 23, 2017

I figured out a way to do this based on the previous answer I already found. This script also doesn't take into account parallel sprints because we don't have that enabled in our instance.

import com.atlassian.jira.component.ComponentAccessor

def sprintField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Sprint")
def sprintName
def allSameSprint = false // initialize to "false" in case none of the issues belong to any sprint

for (issue in issues) {
 def sprint = issue.getCustomFieldValue(sprintField)
 def sprintState = sprint?.state?.last()?.toString()
 if (sprintState.equals("ACTIVE")) {
  // set to "true" sprintName isn't filled yet
  if (sprintName == null) {
   this.sprintName = sprint?.name?.last()?.toString()
   allSameSprint = true
  // set back to "false" if another sprint name is found
  else if (!sprintName.equals(sprint?.name?.last()?.toString())) {
   allSameSprint = false
 // if an inactive sprint is found, set to "false"
 else {
  allSameSprint = false

I'm not the most graceful coder, so if someone knows of a better, more elegant way to do the same thing, please let me know. :)



I can't find the "state" property anywhere in the documentation. Tried:


I'm trying not to depend on implementation details, but rather on documented API features.

same problem.  I would believe that the sprint field returns some sort of collection of sprints, and not the sprint itself, but still the line defining sprintState doesn't make sense to me, and won't compile in the groovy script runner as written

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Wednesday in Jira

Make your Atlassian Cloud products more secure: our NEW admin security guide

Hey admins! I’m Dave, Principal Product Manager here at Atlassian working on our cloud platform and security products. Cloud security is a moving target. As you adopt more products, employees consta...

135 views 0 6
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you