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

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

Bhupesh Nagda April 28, 2015

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Bhupesh Nagda April 30, 2015

NVM 

I figured it out

Jason Smith July 10, 2015

What was the solution?

Jason Smith July 10, 2015

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

Bhupesh Nagda July 12, 2015

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

Jason Smith July 13, 2015

That did it, thanks!

1 vote
Piotr Zielinski June 20, 2016

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?

0 votes
Bhupesh Nagda April 28, 2015

Is there anyone who can hep me on this?

TAGS
AUG Leaders

Atlassian Community Events