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

Script Runner set assignee in a post function

I must be missing something in this simple script. It's a post function (not in the Create transition). The logs appear just as expected, the user in question can be assigned the issue via the UI, the custom field exists. But the assignee is never changed in the issue.

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Category
import com.atlassian.jira.issue.MutableIssue

 * The template script for setting the assignee from a custom user picker
 * Make sure the user chosen is assignable.

def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction");
def issueManager = ComponentAccessor.getIssueManager();
def customFieldManager = componentManager.getCustomFieldManager();
def cf = customFieldManager.getCustomFieldObjectByName("Source User");
if (cf == null) {
    log.error("No custom field found");
def user = issue.getCustomFieldValue(cf);
if (user != null) {
    def user2 = user.getDirectoryUser();
    log.error("Setting assignee to: " + user2.getName());
    log.error("Issue type : " + issue.getClass().getName());
    MutableIssue mutableIssue = issueManager.getIssueObject(

I've also tried using

MutableIssue myIssue = issue

1 answer

The script works fine. The problem was that the workflow I was testing it with had another post function lower down that set the assignee to the current user. I should take my own advice and stay away from the default JIRA workflows and the unexpected stuff that lurks in them :-)


I would stay with MutableIssue myIssue = issue, because otherwise you may get index problems.

You can just reference "issue" without declaring it... I tend to use the construct Henning posted only because then you get typing help from the IDE.

Agree with not reloading the issue though... this will reload the issue from the db and disregard what the user just entered on the form - depending on the ordering of the post-functions.

Got it. I forgot that IssueImpl is already a MutableIssue.

I tried above script and get below error. Please let me know how to resolve it and the proper syntax as I am new to Groovy.

2014-07-24 00:16:30,371 http-17000-14 ERROR ikkhan 16x14831x1 j02hwu, /secure/WorkflowUIDispatcher.jspa [onresolve.jira.groovy.PostFunction] Issue type : com.atlassian.jira.issue.IssueImpl

No information there.

I am trying to use the same script but I'm seeing this line gives an error

MutableIssue myIssue = issue

The script could not be compiled:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script227.groovy: 29: unable to resolve class MutableIssue 
 @ line 29, column 14.
   MutableIssue myIssue = issue

Anything obvious?

Maybe you forgot to copy the import statements in the script? Regarding your error message the following line is missing

import com.atlassian.jira.issue.MutableIssue

<Embarrassed face>

Is this issue resolve ?.


Please post correct script for it, we are also facing same issue

After much playing around we found existing functionality from "Assign From Field This function assigns issue to user from the custom field.".  Part of the script runner, so no need for custom scripting

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Marketplace Apps & Integrations

Localize Smarter with the Transifex Integration for Bitbucket

Over 52% of internet users say obtaining information in their own language is more important than price and 75% of the world’s population doesn’t speak English. It’s no wonder then that successful gl...

224 views 0 3
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