Set assignee based on custom field value


I want to add a postfunction script that sets the assignee based on a custom fields value.

So for example when field a has value 1 then it should be assigned to person 1. If it's value 2 then it should be person 2. We do have scriptrunner, can anybody tell me how the script should look to enable this?

1 answer

1 accepted

This widget could not be displayed.
Vasiliy Zverev Community Champion Oct 25, 2016

Here it is. It could be some changed based on custion field type.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

String userName;

    case "1": userName = "user1";break;
    case "2": userName = "user2";break;
    case "3": userName = "user3";break;    


Thanks Vasiliy! Greatly appreciated!



I have a similiar task to perform, but instead of the assignee I want to set the UserPicker-field, which we use for defining the approver.

Therefor the script should only be valid for our two workflows, which have approval-steps.

So if our employees enter their department, the manager should be set automatically for the following approval.

Best regards, Thomas

Hi @Vasiliy Zverev,


I have the exact same problem to solve, but when I used your corde in a Jython post-function script I get the following error:


SyntaxError: ("mismatched input 'userName' expecting NEWLINE", ('<string>', 4, 7, 'String userName;\n'))

It seems that you have tried to perform an illegal workflow operation.


Do you have any idea why this is happening?

My code so far is:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

String userName;

switch(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Custom Field").toString()){
case "A": userName = "User A";break;
case "B": userName = "User B";break;
case "C": userName = "User C";break;


where "Custom Field" is a custom field defined by a single-choice select-list. 


Thanks in advance!

Best regards,


Hello Hector, 

You can try this script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

String user;

def cfManager = ComponentAccessor.getCustomFieldManager();
def cf = cfManager.getCustomFieldObjectByName("Select List Field");

switch(issue.getCustomFieldValue(cf) as String){
case "1": user = "username1";break;
case "2": user = "username2";break;
case "3": user = "username3";break;


Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

189 views 3 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you