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

This widget could not be displayed.
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. :)

Hi,

 

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

257 views 5 0
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