Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Subtask assignee are not modified on listener

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?

1 answer

Suggest an answer

Log in or Sign up to answer
1 vote
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Aug 12, 2022

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)
TAGS
AUG Leaders

Atlassian Community Events