I'm trying to set my assignee based on components and a select custom field value. For some reason, it is not picking up the correct user. When I choose component "Hardware" and Location "Rotterdam", it would be username1. When I choose component "Hardware" and Location "Utrecht", it would also be username1. Same goes with the last option. I'm not too sure why the if-else statement is behaving this way. Any help? Any ideas?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.customfields.manager.OptionsManager
final String user1 = 'username1'
final String user2 = 'username2'
final String user3 = 'username3'
def one = ComponentAccessor.getUserManager().getUserByName(user1)
def two = ComponentAccessor.getUserManager().getUserByName(user2)
def three= ComponentAccessor.getUserManager().getUserByName(user3)
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Location'}
def cfConfig = cf.getRelevantConfig(issue)
// select custom field values
def utrecht = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.toString() == 'Utrecht' }
def rotterdam = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.toString() == 'Rotterdam' }
def copenhagen = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.toString() == 'Copenhagen' }
//Component
def isHardwareSelected = issue.components*.name.contains('Hardware')
if(rotterdam && isHardwareSelected){
issue.setAssignee(one )
}else if(utrecht && isHardwareSelected){
issue.setAssignee(two)
}else if(copenhagen&& isHardwareSelected){
issue.setAssignee(three)
}
Hi @Filzah Aziz
I don't find any issue with your script except the method you are trying to fetch selected custom field(Location) option.
If I'm not wrong your script choose the 1st one always when hardware is selected irrespective of location, if so that is expected
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName("Location")[0]
String val = issue.getCustomFieldValue(cfSelect) as String
if((val == "Utrecht")&& isHardwareSelected){
issue.setAssignee(one )
}else if((val == "Rotterdam") && isHardwareSelected){
issue.setAssignee(two)
}else if((val== "Copenhagen")&& isHardwareSelected){
issue.setAssignee(three)
}
Best Regards,
Leo
Yes indeed! Thanks for that- i've added your bit to my script :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.