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 widget could not be displayed.

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
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 New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

158 views 2 0
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