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 Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

306 views 4 9
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