ScriptRunner - Scripted Field for PRevious/Current/Next sprint

Daniel Anglin April 12, 2018

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
Erik Buchholz
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 22, 2021

Hi @Daniel Anglin ,

the answer from @Alexey Matveev 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 https://gist.github.com/jechlin/9789183

Regards

0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 12, 2018

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.issue.search.SearchProvider;
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 = searchProvider.search(query, user, PagerFilter.unlimitedFilter)
results.issues.collect
{ issue -> issueManager.getIssueObject(issue.id) }
}

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
TAGS
AUG Leaders

Atlassian Community Events