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
4,365,309
Community Members
 
Community Events
168
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 https://gist.github.com/jechlin/9789183

Regards

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.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

Atlassian Community Events