Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

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

0 votes

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

Atlassian Community Events