Removing Issues from Sprint using ScriptRunner or the Java API

Hey fellow JIRA users, 

I know it's not the "agile" way, but here is what I want to do: 

I want to dynamically remove an issue from the current sprint once it transitions to a certain status. Whether the issue is removed from the sprint is calculated based on some properties. Additionally, the issue type should be changed. 

Calculating the properties and changing the issue type is not a problem. Removing it from the sprint however is. 

The things I found online are suggesting to use the SprintHelper or SprintManagerImpl classes from the greenhopper-package. However, those classes are only taking a Collection or a List of issues are are throwing an exception when using an implementation of those interfaces e.g. ArrayList. 

I'm aware that there is a build-in script in ScriptRunner, but how can I use this script inside a post function / custom script? 

I saw that a similar question has been asked here but there has been no answer.

Thank you very much!

2 answers

1 accepted

0 votes
Accepted answer

Came across this git and adapted the code a bit to fit my needs.

import com.atlassian.greenhopper.service.sprint.Sprint
import com.atlassian.greenhopper.service.sprint.SprintIssueService
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.ContextBaseScript
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import groovy.transform.BaseScript

@BaseScript ContextBaseScript baseScript
def issue = getIssueOrDefault("TP-1")

SprintIssueService sprintIssueService

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def sprintsForIssue = sprintIssueService.getSprintsForIssue(loggedInUser, issue)
Sprint activeSprint = sprintsForIssue.getValue().find{}

if (activeSprint) { "Adding issue $issue to ${} with sprint id ${}"
sprintIssueService.removeIssuesFromSprint(currentUser, activeSprint, [issue] as Collection)
else { ("could not find active sprints for isse ${issue.key}")


Are there any other suggestions? :) 

Thanks for the suggestion! If it's not working using the Java API, I will give it a try! However, I would prefer the "Java API" way.

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,741 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