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

ScriptRunner - Scripted Field for PRevious/Current/Next sprint

I'm trying to develop a scripted field which will show if an issue is in the previous, current, or next sprint.


Any help?

2 answers

Hi @Daniel Anglin ,

the answer from @Alexey Matveev _Appfire_ is good but not completely right.

With openSprints() you get active and future sprints while

sprint in openSprints() AND sprint not in futureSprints()

would give you the issues in active sprints.

On the other hand all issues that where in any now closed sprint will be in the JQL

sprint in closedSprints()

because sprint is a list of all sprints this issue was worked in.

If you want to know if an issue was completed in the previous sprint this JQL won't help you but scriptrunner gives you the JQL

issueFunction in previousSprint('Board name')

Actually I would prefer to use the information of the sprint from the issue directly

import com.atlassian.jira.component.ComponentAccessor

def cfManager = ComponentAccessor.getCustomFieldManager()
def field = cfManager.getCustomFieldObjectsByName('Sprint')
def lastSprint = issue.getCustomFieldValue(field)?.last()

To check if any of the (closed) sprints is the previous sprint use the sprintManager to get all sprint from your board as in example from Jamie Echlin at


0 votes

You could create a scripted field and then if an issue is in a closed spring then the "key = " + issue.key + " and sprint in closedSprints()" must return the value. If the issue is in the current sprint then the the "key = " + issue.key + " and sprint in openSprints()" must return a value. Else the issue is in a future sprint.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.jql.parser.JqlQueryParser;
import com.atlassian.jira.web.bean.PagerFilter;
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.config.FieldConfig
import com.atlassian.jira.issue.context.IssueContextImpl
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.Issue

def findIssues(String jqlQuery) {
def issueManager = ComponentAccessor.issueManager
def user = ComponentAccessor.jiraAuthenticationContext.user
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)

def query = jqlQueryParser.parseQuery(jqlQuery)
def results =, user, PagerFilter.unlimitedFilter)
{ issue -> issueManager.getIssueObject( }

def issues = (List<Issue>) findIssues("key = " + issue.key + " and sprint in closedSprints()")
if (issues.size() >  0) {
    return "previous"
issues = (List<Issue>) findIssues("key = " + issue.key + " and sprint in openSprints()")
if (issues.size() >  0) {
    return "current"
return "next sprint"

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

723 views 7 24
Read article

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