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

This widget could not be displayed.

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()
This widget could not be displayed.

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

This widget could not be displayed.

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 Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Jul 25, 2018 in Marketplace Apps

Jira Cloud and Bitbucket Cloud Integration with Microsoft Teams

One of the newest products in the Microsoft family - Microsoft Teams,  is a chat-based hub for teamwork that integrates all the people, content, and tools your team needs to be more engaged and ...

716 views 0 3
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