JIRA 7 has broken groovy post-function to assign sprint?

So I built a script post-function based on one I found from Jamie about setting an issue to a sprint (mine sets based on a custom field). This script works fine on JIRA 6, but upgrading to JIRA 7, it's throwing me an error:

"[Static type checking] - Cannot find matching method com.atlassian.greenhopper.service.sprint.SprintIssueService#addIssuesToSprint(com.atlassian.jira.user.ApplicationUser, java.lang.Object, java.util.List). Please check if the declared type is right and if the method exists."

I know the API has changed up a bit and is no longer working with GenericValues, but even after I started casting all my variables (which, on all of my other scripts, I haven't yet had to do), it still throws only this error.

Is there something that's changed about the addIssuesToSprint function? Or do I just need to cast my variables in better ways? Thanks!

import com.atlassian.greenhopper.service.rapid.view.RapidViewService
import com.atlassian.greenhopper.service.sprint.SprintIssueService
import com.atlassian.greenhopper.service.sprint.SprintManager
import com.atlassian.greenhopper.service.sprint.SprintService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Category
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

//Set Variables
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfSprint = customFieldManager.getCustomFieldObjectByName("Sprint")
def cfAgileBoard = customFieldManager.getCustomFieldObjectByName("Agile Board")
def sprints = issue.getCustomFieldValue(cfSprint)
def agileBoard = issue.getCustomFieldValue(cfAgileBoard)
def rapidBoardId = 0

//See if the issue is already in an active sprint
if (sprints != null) {
	for (i in sprints.size) {
        ii = i-1
        isprint = sprints.get(ii)
        istate = isprint.state.toString()
        if (istate == "ACTIVE") {
        	log.info("Issue is already in active sprint")

//Sets to a specific board for all issues in a certain project
if (issue.getProjectObject().getKey() == 'KEY') {

//Sets to an agile board based on a custom field
switch (agileBoard) {
	case "Agile Board 1":
	case "Agile Board 2":
	case "Agile Board 3":
	case "Agile Board 4":
	case "Agile Board 5":
        log.info("Agile Board field is empty")

//Performs the actual sprint setting
public setBoard(rapidBoardId) {
	RapidViewService rapidViewService
	SprintService sprintService
	SprintIssueService sprintIssueService
	SprintManager sprintManager
	def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
	def view = rapidViewService.getRapidView(loggedInUser, rapidBoardId).getValue()
	def boardSprints = sprintManager.getSprintsForView(view).getValue()
	def activeSprint = boardSprints.find { it.active }
    def boardName = view.getName()
	if (activeSprint) {
		sprintIssueService.addIssuesToSprint(loggedInUser, activeSprint, [issue])
        log.info("Auto-setting Sprint to active sprint of board: $boardName")
    else {
        log.info("$boardName has no active sprint")

1 answer

1 accepted

There is now a built-in script to handle this: https://scriptrunner.adaptavist.com/latest/jira/builtin-scripts.html#_add_remove_from_to_active_sprint

But I'm not sure you will be able to use it if you need to dynamically set the board based on your rules. JA is not a public API, and it changes often, so if you can use the built-in script that would be easier.

You will need to replace addIssuesToSprint with moveIssuesToSprint ... that might be all. I'm not convinced that this method for getting the first active sprint works properly, but please make that change and have a try.


I did want to use your new built-in script, but the dynamic board setting is a requirement of the script I'm afraid. That said, the simple change worked perfectly! Luckily we don't have parallel sprints active so hopefully we don't need to worry about having to find multiple active sprints per board, but I think in worst case I could probably work up getting a list of active ones and find the 'first' one if need be. Kinda unfortunate they're not maintaining the JA API documentation the same way they are the regular JIRA API docs, but I suppose that's a risk I'll take. Thank you very much!

No problem. As it stands, the code will pick the *first active sprint*, so you should not need to make changes if you have multiple active sprints. They will come in order of creation IIRC.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,711 views 17 21
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