Create Multiple Assignees in an Atlassian JIRA Issue using ScriptRunner
William Yeack

Here at Member.buzz we wanted to create multiple assignees for a JIRA issue where each assignee was responsible for a different part of the issue's workflow.

For example, let's say you have a technical task with the following steps:

In this scenario, we would have to have two people involved, an Engineer should be responsible for most of the work but when the issue is in Testing we would want a Tester to be assigned.

Since JIRA allows us a single assignee for a given issue, we'll use the ScriptRunner plugin by Adativist to create a listener that will modify the assignee whenever a change occurs in the issue, setting the assignee to the correct user.

Create Custom Fields

First, make sure that you create two custom User Picker fields to contain the additional assignees.

Create Listener
Navigate to the Scriptrunner section of your JIRA's administration section and select listeners.configuration and create a listener for all issue events (that way it will update the assignee on workflow transition and if you change any of the relevant fields).

Write Script
Finally, insert the following script (created with help from Adaptivist's awesome support):

    import com.atlassian.jira.component.ComponentAccessor
    import com.atlassian.jira.event.type.EventDispatchOption
    import com.atlassian.jira.issue.Issue
    import com.atlassian.jira.issue.CustomFieldManager
    import com.atlassian.jira.issue.MutableIssue
    import com.atlassian.jira.issue.comments.CommentManager
    import com.atlassian.jira.issue.fields.CustomField
    import com.atlassian.jira.util.ImportUtils
    import com.atlassian.jira.user.util.UserManager
    import com.atlassian.crowd.embedded.api.User
    import com.atlassian.jira.user.ApplicationUser

    def issue = event.issue as MutableIssue;
    def customFieldManager = ComponentAccessor.customFieldManager;

    ApplicationUser fieldValue = null;

    if (issue.status.name == "Testing")
    {
    fieldValue = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjects(issue).find { it.name == "Tester" }) as ApplicationUser;
    }
    else
    {
    fieldValue = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjects(issue).find { it.name == "Engineer" }) as ApplicationUser
    }

    if (fieldValue != null)
    {
    if (issue.assignee)
    {
    if (fieldValue.getUsername() == issue.assignee.getUsername())
    {
    return;
    }
    }

    def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
    issue.setAssignee(fieldValue);
    ComponentAccessor.issueManager.updateIssue(currentUser, issue, EventDispatchOption.ISSUE_UPDATED, false);
    }⁠

Using this script as a starting point, you can create all sorts of cool workflows!

To add a comment, please Register or Login.