Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Script Runner setting Assignee on Issue

Will C
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 30, 2018

Hi there,

I am looking at ways of setting the assignee on a workflow post function. Firstly I have been testing this out using the script runner console with the following piece of code that I seen Stephen Cheesley posted here 

 

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.getIssueManager()
def issueService = ComponentAccessor.getIssueService()
def userManager = ComponentAccessor.getUserManager()

def user = userManager.getUserByName("tbas")

def issue = issueManager.getIssueObject("HW_TEST-64")

def validateAssignResult = issueService.validateAssign(user, issue.id, issue.reporterId)
issueService.assign(user, validateAssignResult)

 

However whenever I used this script in the console it sets the assignee to whoever the reporter is on that issue, no matter who I define it should be in the script.

Am I missing something obvious here?

6 answers

1 accepted

1 vote
Answer accepted
Will C
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 17, 2020

came back to look at my old questions now I have been using Scriptrunner for a bit longer and have built up more experience.

The way to do this is the following:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

def issueManager = ComponentAccessor.getIssueManager()
def issueService = ComponentAccessor.getIssueService()
def userManager = ComponentAccessor.getUserManager()

def user = userManager.getUserByName("user")
def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def assigneeUpdate = issue.setAssignee(user)
issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.ISSUE_UPDATED, false)
1 vote
Danyal Iqbal
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 30, 2018

validateAssign(ApplicationUser user, Long issueId, String assignee)

the reporter is set as id coz you explicitly set it to issue.reporterId.

use instead

def validateAssignResult = issueService.validateAssign(user, issue.id, user)
Will C
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 30, 2018

Thankyou! school boy error it seems.

Although I've tried running it with your suggestion but it still doesn't set the Assignee to the user I set in the script and there are no errors when I try to run it.

0 votes
Will C
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 27, 2018

I am still looking at doing this, just to give some more background.

 

my end goal is that I can copy a project including some issues over to a new project - this is working fine.

Now I want to be able to change the assignee of the copied issues to somebody who I stipulate in the script or choose from a custom field.

I have got the copy project working from a workflow post function but now need to be able to change the assignee, I was thinking within the same script would be best? unless there are other methods I am not thinking of?

0 votes
Will C
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 4, 2018

Thanks for all of the replies so far, I am still unable to change the assignee of an issue using scriptrunner console, any ideas?

0 votes
Moses Thomas
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 30, 2018 edited

see-above.

0 votes
Moses Thomas
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 30, 2018

@Will C

You  may want to  do it this way base on a custom-field option-value(internal) on the  create issue screen in this case.

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.issue.fields.CustomField

 
CustomField cf86903 = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_86903")

String cf86903Value = issue.getCustomFieldValue(cf86903)

if(cf86903Value == 'Internal') issue.setAssigneeId("groovy_m")

Suggest an answer

Log in or Sign up to answer