Set Assignee in Post Function

On Create Issue transition need to set the assignee to a different user using Groovy Script . I have Script runner plugin installed. The following is the script which import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue 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.DefaultUserManager import com.atlassian.crowd.embedded.api.User MutableIssue issue = issue UserManager userManager = UserManager.getInstance(); User usera = userManager.getUser('my_user_name'); issue.setAssignee(usera); It provides me with the below error on execution Script15.groovy: 13: unable to resolve class UserManager @ line 13, column 13. UserManager userManager = UserManager.getInstance(); ^

3 answers

1 accepted

You can try:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
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
// added line no.1
import com.atlassian.jira.component.ComponentAccessor

// added line no.2
userManager = (UserManager)  ComponentAccessor.getUserManager()
MutableIssue issue = issue
  
User usera = userManager.getUser('my_user_name');
   
issue.setAssignee(usera);

Yes , it works Also need to add issue.store()

Posting code formatted as code in a readable way (CR/LF...) will increase your chances of getting help...

0 vote

According to previous discussion on this in here. Mizan suggested to try use the following instead

ComponentManager.getInstance().getUserUtil().getUser('ngs')

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 May 30, 2018 in Marketplace Apps

Three tips for boosting your board's efficiency with Story Maps

Trello is one of the most effective tools for driving your sprints. It's customizable for every Agile team and product owners and Scrum masters (SM) love it. However, Agile teams often struggle with:...

832 views 2 9
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