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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published yesterday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

71 views 0 5
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