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)
issue.setAssignee(user)
System.out.println("If condition executed")
}
else
{
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==>

PostFunctionOrder.png

User has the Assignable User Permission.

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

Thanks!!

3 answers

1 accepted

This widget could not be displayed.

NVM 

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!

This widget could not be displayed.

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

postfunction_error.png

 

Anyone that could help me?

This widget could not be displayed.

Is there anyone who can hep me on this?

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 Teamwork

What teamwork quotes inspire you?

Hey everyone! My name is Natalie and I'm an editor of the Atlassian Blog and I've got a question for you: What's your favorite quote about teamwork?  We've compiled a list here, along with...

192 views 18 7
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