Error in passing component lead to the Assignee?

Hi, On a certain condition i would like to copy the value of the component lead (of component selected) to the Assignee field via custom groovy script which i have placed on a create issue transition but i am getting the below error on the script runner compiler, Can someone please help me to get the proper code to pass the users between these two fields?

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.DelegatingApplicationUser;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.util.IssueChangeHolder;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.crowd.embedded.api.User;

def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def cfQEAssignee = customFieldManager.getCustomFieldObjectByName("QE Assignee");
def QEAssigneeValue = issue.getCustomFieldValue(cfQEAssignee);


if(QEAssigneeValue == null){
	
	issue.assignee = issue.getComponentObjects().getAt(0)?.getLead();
}

 

Exception.png

1 answer

2 votes

Use .assigneeId rather than .assignee

@Jamie Echlin (Adaptavist), Thanks for the quick response. 

Proceeding forward, I am not able to copy the value from a user-picker field to the assignee. Can you please help me with that.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.DelegatingApplicationUser;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.issue.util.IssueChangeHolder;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.crowd.embedded.api.User;
def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def cfQEAssignee = customFieldManager.getCustomFieldObjectByName("QE Assignee");
def QEAssigneeValue = issue.getCustomFieldValue(cfQEAssignee);
if(QEAssigneeValue == null){
	
	issue.assigneeId = issue.getComponentObjects().getAt(0)?.getLead();
}
if(QEAssigneeValue != null){
	issue.assigneeId = QEAssigneeValue;
	
}

Since you're setting the assigneeId, you need to use the user key, not a user object.

issue.assigneeId = issue.componentObjects[0]?.lead?.key

...then in the next block

issue.assigneeId = QEAssigneeValue.key

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

24 views 0 4
Read article

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