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

1 vote

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

754 views 2 19
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