Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

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( as MutableIssue;
if (i.getTo() != null) {
def assignee = userManager.getUserByKey(i.getTo())
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

1 vote

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)

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

214 views 1 6
Read article

Atlassian Community Events