Post-function script to set Assignee based on custom drop-down selection

Hello,

I am using Script Runner (LOVE this add-on!) to create a post-function script to set Assignee based on a custom field drop-down selection.  I am using the below script but can't seem to get it to work.  Any ideas on what I am missing here?  I am a bit of a novice when it comes to scripting.  Thanks!

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
  
MutableIssue issue = issue
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
CustomField customFieldX = customFieldManager.getCustomFieldObject("customfield_10022")
def xFieldVal = issue.getCustomFieldValue(customFieldX)
if(xFieldVal == "Client Operations" ){
   User userA=ComponentManager.getInstance().getUserUtil().getUser('lbantug')   
   issue.setAssignee(userA);
   }
issue.store()

1 answer

this works ...

 

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.UserManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor

userManager = (UserManager) ComponentAccessor.getUserManager()
MutableIssue issue = issue

CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
CustomField customField_name = customFieldManager.getCustomFieldObjectByName( "LeadComponent" );
def comp = issue.getCustomFieldValue(customField_name);

def str = comp.toString().toLowerCase();
def userToReassign = issue.getAssignee()

 

switch ( str ) {
case "XY" :
userToReassign = userManager.getUser('AB');
break
case "YX" :
userToReassign = userManager.getUser('BA');
[...]

break

default :
userToReassign = userManager.getUser('CD');
}

issue.setAssignee(userToReassign);
issue.store();

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,300 views 14 20
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot