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
Community showcase
Posted Sep 25, 2018 in Jira

Atlassian Research Workshop opportunity on Sep. 28th in Austin, TX

We're looking for participants for a workshop at Atlassian! We need Jira admins who have interesting custom workflows, issue views, or boards. Think you have a story to sha...

469 views 7 5
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