Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Listener - Setting assignee based off Component Lead

patricia_scott_honeywell_com
May 20, 2022

I have a custom scriptrunner listener that checks if the Components field was updated, and if it was retrieve the Component lead for the first component in the list.  Then I want it to set the assignee to that component lead.

I know it is retrieving the component lead correctly, but the script is not setting the assignee as expected and I am not sure why.

I must be missing something, can someone help me know what I am doing wrong?  Here is my code:

 

import com.atlassian.jira.event.issue.IssueEvent;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import org.ofbiz.core.entity.GenericValue;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.util.UserManager;

def int icount = 1
def String DefaultAssignee = ""

// Checking if the "Components" field value has changed.
def event = event as IssueEvent;
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager();
def issue = event.getIssue() as MutableIssue;

def changelog = event.getChangeLog();
def changedFields = findFieldsMentionedInChangeLog(changelog)

// Component field has changed, then set the Component Lead as the Assignee
if (changedFields.contains("Component")) {
    // def String ComponentName = issue.components.name
    def String ComponentDefaultAssignee = issue.components.lead
    def ilength = ComponentDefaultAssignee.length()

    // If Component has multiple values, retrieve the Lead for the first component.
    if (ilength > 0) {
        while (icount <= 7) {
            DefaultAssignee = DefaultAssignee + ComponentDefaultAssignee[icount]
            icount = icount + 1
        }

        // Find the user name for the user to set as the assignee
        def user = ComponentAccessor.userManager.getUserByName(DefaultAssignee)

        // Set the assignee field to the component lead
        issue.setAssignee(user)
        issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
    }
}

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events