Missed Team ’24? Catch up on announcements here.

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

Subtask assignee are not modified on listener

Pablo A. Revert
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 12, 2022

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.
August 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