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

jira groovy issue assigned problem

AbrahamA Jun 30, 2016

 

Hello

Issue is getting assigned to number (Ex: 13329) instead of user. Here is my script

How can I get it assigned to user instead of number.

(Also any better way to save I see warning symbol)

Please let me know.


Thanks

Abe

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.security.roles.ProjectRole
import com.atlassian.jira.security.roles.ProjectRoleActors
import org.apache.log4j.Category
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.user.ApplicationUser

def log = Logger.getLogger("com.sam.parallel")
log.setLevel(Level.DEBUG) 
//Issue issue = issue
def issueManager = ComponentAccessor.getIssueManager();
Issue issue = issueManager.getIssueObject("SIG-22" )
Project project = issue.getProjectObject()
//log.debug(project.getName())
UserManager userManager = ComponentManager.getComponentInstanceOfType(UserManager.class) as UserManager
def currentAssignee = issue.getAssignee()
ComponentManager componentManager = ComponentManager.getInstance()
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
// Get Parallel Approver Project Role
ProjectRole approverProjectRole = projectRoleManager.getProjectRole("Parallel Approvers")
ProjectRoleActors myAppro = projectRoleManager.getProjectRoleActors(approverProjectRole, issue.projectObject)
Set users = myAppro.getUsers()

Collection alist = new ArrayList()
users.each {
    alist.add(it.getId())    
}
Collections.shuffle(alist)
// Assign issue to first user after shuffle
log.debug( alist.get(0).toString() )
issue.setAssigneeId(  alist.get(0).toString()  )
issue.store()


1 answer

2 votes
AbrahamA Jun 30, 2016

ok found it needed to put key instead of id.

users.each {
alist.add(it.getKey())
}

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

664 views 7 0
Join discussion

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