Forums

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

Assignee populated with custom field (user picker) on transition

Lena Hansen March 7, 2018

Jira version: v7.7.1

Scriptrunner version: 5.3.7

I found a script similar to the one below that I would like to implement using script runner. 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser

// Get required Managers
def customFieldManager = ComponentAccessor.getCustomFieldManager()

// get a pointer to the Implemented By user picker field and its value
def userCf = customFieldManager.getCustomFieldObjectByName("Developer")
def implUser = issue.getCustomFieldValue(userCf) as ApplicationUser

// If the Implemented By Field is not null then set the assignee
if(implUser){
issue.setAssigneeId(implUser.username.toString())
}

 

I have the script runner add-on, but when I put the above script in script-console, I get an error "the variable [issue] is undeclared". What am I missing? 

Any help is greatly appreciated. 
Thank you.

1 answer

0 votes
Jenna Davis
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.
March 21, 2018

Hello, 

Sorry for such a late reply on this!

I believe you just need to make your issue into a Mutable issue so that you have access to the setAssignee() method. You can do so by adding this line near the top of your code, below the import statements:

MutableIssue issue = issue as MutableIssue

You'll also need to add in the import for the Mutable Issue class, which can be done like so:

import com.atlassian.jira.issue.MutableIssue 

Please let me know if this fixes the problem that you're seeing, or if you have any other questions. 

Jenna

Lena Hansen March 21, 2018

Thank you for your response Jenna.

I actually got my script to work. I was adding it to the wrong place apparently. It works when I add it in my jira workflow by creating a post function (Script Post-Function).

I was previously trying to add it under “add-ons”, “script runner”, “script console”.

Jenna Davis
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.
March 21, 2018

Great! I'm glad you got it working. :)

Just for future reference, the script console is where you would place script you want to be ran once on the entire instance. You were likely getting the '[issue] is undeclared' error because a specific issue isn't defined for the script console, you have to get the issue yourself if you want to run a script there using the IssueManager's getIssueByCurrentKey() method or something similar. 

I would recommend that you read over the ScriptRunner documentation for more information on what you can do with the different types of scripts.

Jenna  

Lena Hansen March 21, 2018

That is very helpful. Thanks again!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events