I am looking to set the assignee of an issue based on 2 fields, where the 2nd field is a user picker field.
In plain English, here's what I'm looking to do:
- If FieldA = Apple, then set assignee to value in user picker field called "Apple Picker"
- If FieldA = Blueberry, then set assignee to value in user picker field called "Blueberry Picker"
- If FieldA = Cherry, then set assignee to value in user picker field called "Cherry Picker"
Here's the code I've strung together from other posts. I'd love some help.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
String user;
def cfManager = ComponentAccessor.getCustomFieldManager();
def cf = cfManager.getCustomFieldObjectByName("FieldA");
def applepicker= ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Apple Picker")
def assignee1 = issue.getCustomFieldValue(applepicker)
def blueberrypicker= ComponentAccessor.customFieldManager.getCustomFieldObjectByName("BlueberryPicker")
def assignee2 = issue.getCustomFieldValue(blueberrypicker)
def cherrypicker= ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Cherry Picker")
def assignee3 = issue.getCustomFieldValue(cherrypicker)
switch(issue.getCustomFieldValue(cf) as String){
case "Apple": user = assignee1;break;
case "Blueberry": user = assignee2;break;
case "Cherry": user = assignee3;break;
}
issue.setAssignee(ComponentAccessor.getUserManager().getUserByKey(user))