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
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.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,811 views 11 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot