• Community
  • Products
  • Jira
  • Questions
  • how do I use the Issue Assignment Listener to automatically set the assignee of all sub-tasks to match the parent?

how do I use the Issue Assignment Listener to automatically set the assignee of all sub-tasks to match the parent?

We are using JIRA 6.0.8. I do not want to base this on a workflow transition because the assignee could be updated on a parent issue at any time without changing the workflow state.

Also, can this be done for only selected projects or will it affect all projects in JIRA?

Thank you,

Jeannette

1 answer

This widget could not be displayed.

You can try this:

package com.atlassian.jira.event.listeners
 
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import org.apache.log4j.Category
import org.apache.log4j.Level
import org.apache.log4j.Logger
 
public class SubtaskAutoAssignListener extends AbstractIssueEventListener {
    Category log = Category.getInstance(SubtaskAutoAssignListener.class)
  
    @Override
    void workflowEvent(IssueEvent event) {
        log.error("\n \n \n \n ---- Assignee Updater starts -----  \n \n \n \n \n")
        CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager()
        def customField_Follow = customFieldManager.getCustomFieldObjectByName( "Subtask Follow" )
        def subtaskFollow = event.issue.getCustomFieldValue(customField_Follow)
        log.error("\n \n \n Assign subtask to parent assignee?: $subtaskFollow \n \n")
        if ("$subtaskFollow" == "Yes") {
            if (!event.issue.isSubTask()){
                def issueAssigneeId = event.issue.getAssigneeId()
                log.error("\n \n \n Parent Issue Assignee: $issueAssigneeId \n")
 
                IssueManager issueManager = ComponentAccessor.getIssueManager()
                UserManager userManager = ComponentAccessor.getUserManager()
 
                event.issue.getSubTaskObjects().each { t ->
                    log.error("\n \n \n Subtask ID: $t \n \n \n")
                    def subtaskAssignee = t.getAssigneeId()
                    log.error("\n \n \n Current subtask assignee: $subtaskAssignee \n \n \n")
                    if (!subtaskAssignee.equals(issueAssigneeId)) {
                        MutableIssue myIssue = t
                        myIssue.setAssigneeId(issueAssigneeId)
                        issueManager.updateIssue(userManager.getUser(issueAssigneeId),myIssue,EventDispatchOption.DO_NOT_DISPATCH, false)
                        def newSubtaskAssignee = myIssue.getAssigneeId()
                        log.error("\n \n \n New subtask assignee: $newSubtaskAssignee \n \n \n")
                    }
                }
            }
        }
        log.error("\n \n \n \n ---- Assignee Updater Ends -----  \n \n \n \n \n")
    }
}

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

88 views 1 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you