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)
    }
}

1 answer

Suggest an answer

Log in or Sign up to answer
2 votes
Charlotte Lim
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 19, 2018

Hi Artem,

Thank you so much for your question.

We're always working hard to improve Jira Service Desk for every user, by balancing the short and long term needs of our customer base.

In this instance, there is currently no such API in Jira Service Desk. If you feel like this is something we must address, please raise a request with Support https://getsupport.atlassian.com.


Thank you,

The Jira Service Desk Team

Artem Grotskyi
Contributor
June 4, 2018

Thank you, @Charlotte Lim

Like Charlotte Lim likes this
TAGS
AUG Leaders

Atlassian Community Events