I'm trying to develop a scripted field which will show if an issue is in the previous, current, or next sprint.
Any help?
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
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"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.