Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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

Find Active Sprint using GroovyScript but when there are multiple projects on a board



This lovely piece of script can be found here: 

import com.atlassian.greenhopper.service.rapid.view.RapidViewService
import com.atlassian.greenhopper.service.sprint.SprintService
import com.atlassian.greenhopper.service.PageRequests
import com.atlassian.greenhopper.service.sprint.SprintQuery
import com.atlassian.greenhopper.service.sprint.Sprint
import com.atlassian.greenhopper.service.sprint.Sprint.State

def boardId = <Board Id>
def board = getComponent(RapidViewService).getRapidView(currentUser, boardId).get()
def SprintService = getComponent(SprintService)
def State = Sprint.getClasses()[1]

def sprintQuery = SprintQuery.builder().states(Collections.singleton(State.ACTIVE)).build()
def sprintsOutcome = SprintService.getSprints(currentUser, board, PageRequests.all(), sprintQuery)

if (sprintsOutcome.isInvalid()){
  throw new UnsupportedOperationException(sprintsOutcome.toString())
def sprints = sprintsOutcome.get().getValues()

if (sprints.size() == 0){
  throw new UnsupportedOperationException("No active sprints")
if (sprints.size() > 1){
  throw new UnsupportedOperationException("More than one sprint is active")
return sprints[0].getId()


It essentially takes a Board ID and returns the associated sprints so you can do clever things like have a self-referencing transition that lets you "Add To Sprint" which just pops the Jira into the active sprint without having to edit and select the sctive sprint from the dropdown. Lazy? Perhaps. But when you're triaging 200 bugs and you just want to click a button and move on, it's a godsend. 

The issue I have is that we have added another project to the board. Hence, I no longer have ONE active Sprint. I now have two. This means this script will always throw the "More than one sprint is active" exception. 

My question is: does anyone know how to modify the code so that it can filter out the active sprint of the project I don't care about? 


Let's say there are two projects on a board called Animals. The projects are called Cat and Dog. Each have their own sprints. 

  • Cat Sprint 3 (Active) 
  • Cat Sprint 2 (Closed) 
  • Cat Sprint 1 (Closed) 
  • Dog Sprint 2 (Active) 
  • Dog Sprint 1 (Closed) 


I want the query above to IGNORE the active Dog sprint and only return the details of Cat Sprint 3. 

Any ideas? 

Is the best option to simply stop throwing the exception for multiple sprints, accept that there could be more than one and do some sort of check (i.e. looking for the "Cat" string) on the sprints[] array? 

Thanks in advance, 




1 answer

1 accepted

2 votes
Answer accepted

Hi @Lee Cash ,

your problem is not related to having more than one project on your Board, because Sprints are not associated with projects but boards. You just have multiple active sprints, and you just happen to only put issues of a single project in each. The only differentiation between your sprints is... their name. Therefore, you could simply filter active sprints based on the name. Just replace:

def sprints = sprintsOutcome.get().getValues()


def sprints = sprintsOutcome.get().getValues().findAll{"Cat ");


Thanks, David. This worked perfectly. I appreciate all your help. 

Suggest an answer

Log in or Sign up to answer

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