Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Looking to set assignee based on cf values using Scriptrunner

I'm looking to have a post function assign a JIRA issue depending on two fields that are of the single select type (Region and Network). Although the JIRA in question has both fields set with values that are described in the IF statement the user assigned is userB. Is there something I'm missing in the script below?


import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;

//define custom field manager
def customFieldManager = ComponentAccessor.getCustomFieldManager()

//define custom fields
def Network = customFieldManager.getCustomFieldObject("customfield_10742")
def Region = customFieldManager.getCustomFieldObject("customfield_14440")
def userA = ComponentAccessor.userManager.getUserByName("John")
def userB = ComponentAccessor.userManager.getUserByName("Maria")

if(Network == "Airport"){

1 answer

1 accepted

1 vote
Answer accepted

Your def Network and def Region lines are not doing what you think.  The variables will contain the objects representing the custom fields, not the content of them.

It's also quite likely that even if you do get the values, the if ( == ) bit won't work - if the fields are select lists, the content of the fields will be Jira "options" not strings.  If that's the case, then you'll want something more like

if ("Airport".equals(networks-value.getName() ) has some sample code about working with custom fields.

Nic, thanks for the explanation and link to examples it really helped! After applying the changes the assignee is being assigned to the correct user based on the contents of the designated custom fields. I'm still a bit green when it comes to creating custom scripts with ScriptRunner, is there a recommended resource you can point me to for learning the ins and outs of it?

Again, thanks for taking the time to answer this for me, truly appreciate it!

I tend to steal a lot from the Library, even the scripts I've written that have made it in there!

But for getting started, I'd skim through the resources at

Like Gustone Lewis likes this

Suggest an answer

Log in or Sign up to answer

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