Hi, I need to update subtasks assignees of issue to "Project Manager" when "Project Manager" field is changed.
I've made a Listener on IssueUpdate with the following script:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.issue.field.AbstractCustomFieldEvent
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def issue = event.issue
if (issue.getIssueType().getName() == "Purchase Order") {
def changes = changeHistoryManager.getChangeHistories(event.issue)
def change = changes.last()
for (i in change.getChangeItemBeans())
if (i.getField() == "Project Manager"){
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def subTaskManager = ComponentAccessor.getSubTaskManager()
IssueManager issueManager = ComponentAccessor.getIssueManager()
def userManager = ComponentAccessor.getUserManager()
Collection subTasks = issue.getSubTaskObjects()
for (s in subTasks) {
def subtask = issueManager.getIssueObject(s.id) as MutableIssue;
if (i.getTo() != null) {
def assignee = userManager.getUserByKey(i.getTo())
log.warn(subtask)
log.warn(assignee)
subtask.setAssignee(assignee)
issueManager.updateIssue(assignee, issue, EventDispatchOption.ISSUE_UPDATED, true)
}
}
}
}
The listener ends ok, and from the log I could check that the subtask are correctly detected, and also is assignee, but when I check the subtasks assignee value has not been changed.
Any one could detecte the incident?
This line
issueManager.updateIssue(assignee, issue, EventDispatchOption.ISSUE_UPDATED, true)
Is attempting to save the source issue rather than the subTask
Change it to
issueManager.updateIssue(assignee, subtask, EventDispatchOption.ISSUE_UPDATED, true)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.