You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
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.