I have written a post function script to check the value of a multi-select list and when I check the field value, I see the option I want but when I attempt to use the contains() or any.equals() methods to validate this in an if/else statement, I am getting a false even when the value should throw a true.
Please find my script below:
import java.util.ArrayList
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
IssueManager issueManger = ComponentAccessor.getIssueManager()
MutableIssue curEpicIssue = issue
CustomFieldManager cfManager = ComponentAccessor.getCustomFieldManager()
CustomField productLineField = cfManager.getCustomFieldObject('customfield_17003')
ArrayList<String> productLineFieldValue = curEpicIssue.getCustomFieldValue(productLineField) //Multi select list field
log.warn("Current Issue " + curEpicIssue)
log.warn("Current Issue's issue type " + curEpicIssue.getIssueType().getName())
log.warn("Value from the Product Line Field " + productLineFieldValue)
log.warn("Class of the Product Line Field " + productLineFieldValue.getClass())
log.warn("Size of the Product Line Field " + productLineFieldValue.size())
log.warn("Does the Product Line field contain the value Others? " + productLineFieldValue.contains("Others")) //any().toString().equals("Others"))
log.warn("Does the Product Line field contain the value identity? " + productLineFieldValue.contains("Identity"))
if(productLineFieldValue){
productLineFieldValue.each {
log.warn("The following values are contained in the Product Line field's array: $it.value")
}
}
and the result returned is below
2024-05-14 10:29:04,367 WARN [runner.ScriptBindingsManager]: Current Issue OPM-15035
2024-05-14 10:29:04,367 WARN [runner.ScriptBindingsManager]: Current Issue's issue type: Epic
2024-05-14 10:29:04,367 WARN [runner.ScriptBindingsManager]: Value from the Product Line Field: [Others]
2024-05-14 10:29:04,367 WARN [runner.ScriptBindingsManager]: Class of the Product Line Field: class java.util.ArrayList
2024-05-14 10:29:04,367 WARN [runner.ScriptBindingsManager]: Size of the Product Line Field: 1
2024-05-14 10:29:04,368 WARN [runner.ScriptBindingsManager]: Does the Product Line field contain the value Others? false
2024-05-14 10:29:04,368 WARN [runner.ScriptBindingsManager]: Does the Product Line field contain the value identity? false
2024-05-14 10:29:04,369 WARN [runner.ScriptBindingsManager]: The following values are contained in the Product Line field's array: Others
From what I see, it contains my expected value but I still get a false when checking if it contains the value others.