Change assignee based on a checkbox

I want to change the assignee of an issue based on a checkbox. if the value "Related" is check in the custom filed "Customer Related", I want the assignee to be change to some one else.

I tried to do the following:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor

def issue = ComponentAccessor.getIssueManager().getIssueObject("ISSUE-1")
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Customer Related");
def selectedValues = customField.getValue(issue)*.value
if ("Related" in selectedValues)
    userManager = (UserManager) ComponentAccessor.getUserManager()
    MutableIssue issue = issue
    User usera = userManager.getUser('Username');

But it did not work, nothing happened.

Thanks alot!

1 answer

There are couple of things needed to be corrected in your code.

Inshort, you can check this post:

Let me know if this works for you :)

Hi Sanjay,

Thanks for the replay.

I am new to groovy so I guess I will have alot of problems at first.

I do not understand how to implement the answer in this post to my problem.

Try these, i haven't checked in any environment, please excuse :

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Customer Related");

instead of this, try for getCustomFieldObject("customfield_xxxx")

where xxxx is the ID of the custom field

Also, issue.getCustomFieldValue(customField) instead of customField.getValue(issue)*.value



if (selectedValues*.value.contains("Related")) {

#Do your stuff


Its still not working for me.

in getCustomFieldObject("customfield_xxxx") I should keep the "customfield" and just change the xxx right?

for example: customfield_1000

it could be a problem with this line?

def issue = ComponentAccessor.getIssueManager().getIssueObject("ISSUE-1")

Yes, you are right 

 Issue issue =

If this doesn"t work then I can come up after checking this in an environment(i don't have right now)

Also I would say to log each step then you will come to know which is causing exact problem.



Also, there could be a problem with those two lines?

Issue issue =


MutableIssue issue = issue

(as they both have the same variable name)

I tried to run this by itself, and it worked, the assignee changed:

    userManager = (UserManager) ComponegntAccessor.getUserManager()
    MutableIssue issue = issue
    User usera = userManager.getUser('Username');

So the problem is with the condition. Still cant figure what it is exactly.

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;

ComponentManager componentManager = ComponentManager.getInstance();
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager();

CustomField customer_Related= customFieldManager.getCustomFieldObject("customfield_xxx");

customer_Related_Value = issue.getCustomFieldValue(customer_Related)

if (customer_Related_Value*.value.contains("Related"))


User usera = userManager.getUser('Username');


Still nothing happends. There could be a problem with the post function order?

At this moment the script is runing right after "Creates the issue originally"

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,949 views 19 22
Read article

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