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

1 vote
Accepted answer

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!

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?

Is there anyone who can hep me on this?

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in United States

Topic Tuesday: What's your favorite topic?

Good morning All, Our goal is to get you into the habit of while enjoying your favorite morning drink you are checking the NOVA "space" for topics and comments. Your input is really needed and...

57 views 4 0
View post

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