So posing this question here is a stretch I know, but I'm hoping to use scriptrunner to create a custom field that calls the count of previous sprints that an issue has been in, in order to calculate how many times it has rolled over. I used this groovy script, and it retrieved the current sprint ONLY:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def sprintCf = customFieldManager.getCustomFieldObjectByName("Sprint")
Issue issue = issue
issue.getCustomFieldValue(sprintCf)
But I want all of the old sprints from change history, not just the current one.
I know I can invoke ChangeHistoryItem function but don't have the groovy skills to get it to work.
I found the api documentation but it doesn't tell me field names so I'm stuck.
Any groovy wizards around?
You can extract all the changes for a specific field like this:
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.greenhopper.service.sprint.SprintManager
@JiraAgileBean SprintManager sprintManager
def chm = ComponentAccessor.changeHistoryManager
def sprintChangeItems = chm.getChangeItemsForField(issue, 'Sprint')
if(!sprintChangeItems) return null
(sprintChangeItems.from + sprintChangeItems.to).unique().findAll().collect{sprintManager.getSprint(it as Long) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.