Hi All
I have this script to assign tickets to users based on values selected in 3 different custom fields. Previously "Detected in Release" was a optional field and 1st "if" statement executed when Detected in Release == null. That worked perfectly and assigned issue to users as expected. Now we have requirement to make it mandatory and have N/A as option. We need to execute "if" when Detected in Release == N/A . But this time it doesn't work and keep assigning tickets to u22222 by skipping the 1st "if". I tried this by using other options in the list. But it acts the same.
In short, Detected in Release doesn't pick options in the list but works fine when "null".
Can somebody help me to find the error in the script?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.event.type.EventDispatchOption
//Defining custom fields
String userName;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("Test Phase")
def cfTestPhase = issue.getCustomFieldValue(cf)
def cfp = customFieldManager.getCustomFieldObjectByName("Project Name")
def cfProjectName = issue.getCustomFieldValue(cfp)
def cfd = customFieldManager.getCustomFieldObjectByName("Detected in release")
def cfDetectedRelease = issue.getCustomFieldValue(cfd)
//Validating values selected in Test Phase and Detected in Release custom fields.
if (cfDetectedRelease == "N/A") {
switch(cfTestPhase){
case "Prod":
userName = "u11111"
break
case "Prod Fix":
userName = "u11111"
break
default :
userName = ""
break
}
}
else {
switch(cfTestPhase){
default :
userName = "u22222"
break
}
}
//Validating the value selected in Project name.
switch(cfProjectName){
case "Project1" :
userName = "p11111"
break
}
log.error("Username chosen: " + userName)
//Assigning the issue to the value picked by userName
if (! userName.isEmpty() ) {
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issue.setAssignee(ComponentAccessor.getUserManager().getUser(userName))
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
}