Hello,
I created a script that gets the name of the sprint of an issue and sets it to a text field.
Although I tried, I could not make it take the first sprint of an issue, in case it has been added to multiple ones. The way I currently have it, it takes the current sprint, and I do not need that.
The script is below. Please let me know if it is possible to get the first ever sprint to which this issue was assigned, and how to achieve that.
Thank you!
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.greenhopper.service.sprint.Sprint
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
def issue = event.issue as MutableIssue
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueManager issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def sprint = customFieldManager.getCustomFieldObjectByName("Sprint")
def sprints = issue.getCustomFieldValue(sprint)
def textfield = customFieldManager.getCustomFieldObjectByName("Initial Sprint Planned")
def plan = issue.getCustomFieldValue(textfield)
if (!sprints) {
return
}
else {
def sprintName = sprints?.name?.first()?.toString()
plan = sprintName
issue.setCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Initial Sprint Planned"), plan)
ComponentAccessor.getIssueManager().updateIssue( ComponentAccessor.getJiraAuthenticationContext().getUser(),issue, EventDispatchOption.ISSUE_UPDATED, false)