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

Unable to Set assignee using ScriptRunner

With the below code - Trying to set the assignee to someone else based on the user (name: Piyush Annadate and userKey as Piyush_Annadate).


This doesn't event assign the issue to other person. What's missing?

 

Scriptrunner- 5.4.49

JIRA  7.13.1 (Server)

 

 

 

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
def log = Logger.getLogger("com.acme.workflows")
log.setLevel(Level.DEBUG)
def issueManager = ComponentAccessor.getIssueManager()
def issueService = ComponentAccessor.getIssueService()
def userManager = ComponentAccessor.getUserManager()
//def issue = issueManager.getIssueObject("HW_TEST-64")

def issue = event.issue
log.info("${issue.projectObject.key}")
log.info("${issue.key}")

def user = ComponentAccessor.getUserManager().getUserByName('Piyush_Annadate')
def validateAssignResult = issueService.validateAssign(user, issue.id, issue.reporterId)
issueService.assign(user, validateAssignResult)

1 answer

1 accepted

0 votes
Answer accepted

The user in issueService.validateAssign and issueService.assign is the user performing the action.

The 3rd argument in validateAssign (String assignee) is the assignee you wish to apply.

Try this instead

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
def log = Logger.getLogger("com.acme.workflows")
log.setLevel(Level.DEBUG)
def issueManager = ComponentAccessor.getIssueManager()
def issueService = ComponentAccessor.getIssueService()
def userManager = ComponentAccessor.getUserManager()
//def issue = issueManager.getIssueObject("HW_TEST-64")
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def issue = event.issue
log.info("${issue.projectObject.key}")
log.info("${issue.key}")

def user = ComponentAccessor.getUserManager().getUserByName('pjp')
def validateAssignResult = issueService.validateAssign(currentUser, issue.id, user.name)
if(validateAssignResult.isValid()){
issueService.assign(currentUser, validateAssignResult)
}

Thanks Peter for the change and the explanation. That worked !! :) 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

The add-in you’ve been waiting for: Jira Cloud for Excel 🙌

Introducing Jira Cloud for Excel Here at the product integrations team at Atlassian, we are thrilled to announce the new Jira Cloud for Excel add-in! This add-in lets you export Jira data directly ...

842 views 5 22
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