Our new Appfire Documentation Space is now live!

Take a look here! If you have any questions please email support@appfire.com

Fetch the current active sprint of a Scrum board

Abstract

This code snippet fetches the current active sprint of a Scrum board.

Logic

Fetch the active sprints applicable to the current user and specified board and get the first sprint.

Snippet

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

Placeholders

Placeholder
Description
Example
<Board Id>

Numerical ID of the Scrum board

2

Examples

The outcome of the code snippet is the current active sprint of the board which you could use to set the Sprint of an issue in one of the Set field value post-functions for example to Add the issue to the current active sprint.

References