Assigning Issue to a user based on value of a custom field

I am using Script Runner plugin and running a custom script with below code to assign issue to a user based on value of a custom field. Custom field is a single select drop-down with 5 options. I am able to capture the value and condition it but I am unable to assign the issue to user using this script. 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.ComponentManager
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
CustomField cf = customFieldManager.getCustomFieldObject(11849);
String value = issue.getCustomFieldValue(cf).toString()
System.out.println("Custom field Value: "+ value)
if(value == 'Production')
String userName="abc"
def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserObject(userName)
System.out.println("If condition executed")
System.out.println("If condition Not executed")

Log Output for positive use case==>

Custom field Value: Production
If condition executed
[DebugMailListener]: Issue: [#101311] test
[DebugMailListener]: Comment: null
[DebugMailListener]: Change Group: null
[DebugMailListener]: EventTypeId: 1
[DebugMailListener]: Time: Tue Apr 28 11:04:19 EDT 2015
[DebugListener]: DebugListener.issueCreated
[DebugListener]: Issue: [#101311] test
[DebugListener]: Comment: null
[DebugListener]: Change Group: null
[DebugListener]: Event Type: Issue Created
[DebugListener]: Time: Tue Apr 28 11:04:19 EDT 2015

Post Function Order==>


User has the Assignable User Permission.

I have been stuck on this for 2 days, can anynone please guide me?


3 answers

1 accepted

Accepted Answer
1 vote


I figured it out

What was the solution?

Where I'm at is that this works during a regular transition, but it doesn't work during the create transition.

Put the script to first spot in the post functions and then try again

That did it, thanks!

Unfortunately, this script post function doesn't work with JIRA 7. After upgrade I received errors like in a screenshot attached.



Anyone that could help me?

Is there anyone who can hep me on this?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published yesterday in Jira Ops

Jira Ops Early Access Program Update #1: Announcing our next feature and a new integration

Thanks for signing up for Jira Ops! I’m Matt Ryall, leader for the Jira Ops product team at Atlassian. Since this is a brand new product, we’ll be delivering improvements quickly and sharing updates...

210 views 0 5
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