Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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(); ^

5 answers

1 accepted

1 vote
Answer 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...

Correct way as of 2020 is using

issue.setAssignee(user)
issueMgr.updateIssue(currUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

 issue.store should not be used in scripts at all, according to message it shows when you put in console:

obrazek.png

 

Whole script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption

UserManager userMgr = ComponentAccessor.getUserManager()
IssueManager issueMgr = ComponentAccessor.getIssueManager()
ApplicationUser currUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

ApplicationUser newAssignee = userMgr.getUserByName("username")

issue.setAssignee(newAssignee)
issueMgr.updateIssue(currUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

API seems to have changed. Nothing on the page worked for me. But this works:

issue.setAssignee(ComponentAccessor.userManager.getUser("someuser"))
issue.store()
0 votes

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
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

79 views 1 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you