Hey folks,
Overview
I'm trying to compare the values returned from a multi-select field on an issue to the key in a map. From the map, I'm attempting to then use the related map value to get the applicable context of a field and set values on a separate field as a behavior.
The Problem
I'm running into issues when iterating through the values returned by the multi-select. Its printing the function correctly, but if I add an `if` to attempt to compare to the map.key it doesn't seem to run through that- I believe this is possible in groovy, but happy to be redirected!
The script I'm using:
def im = ComponentAccessor.issueManager
def issue = im.getIssueObject('AWOLBP-2') //in a workflow postfunction, you can just comment out this line, the script binding already includes an issue variable
log.warn "Using $issue"
def cfManager = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager
// Field and Project Value Map
def projectContextMap = [
'Foo':16601, // for dev testing. comment out in prod.
'Bar':16901 // for dev testing. comment out in prod.
]
def projectContextMapKey = projectContextMap.key
def projectContextMapId = projectContextMap.value
for (e in projectContextMap){ // checking format of the full map
log.warn "key = ${e.key}, Value = ${e.value}"
}
// Field Configuration Area
def productGroup = cfManager.getCustomFieldObjectsByName('Group')
def groupValue = productGroup ? issue.getCustomFieldValue(productGroup[0]) : "Field doesn't exist"
log.warn "Custom field value type or class" + groupValue.getClass()
groupValue.eachWithIndex { it, i ->
log.warn "Group Values $i: $it"
}
def productTeam = getFieldById("customfield_19403") // Product Team(s) Jira Test ID 19403
def productTeamObjects = cfManager.customFieldObjects.findByName("Product Team(s)")
log.warn("ProductTeam Objects: $productTeamObjects")
// Iterate through the Group value list and add context values
for (i in groupValue){
log.warn "Present Value for $issue: $i"
if (projectContextMap.containsKey(i)) {
return true //I expect this part to be returning something if the value is `Foo`
log.warn "$i matched with ${projectContextMap.value}"
}
}
The error:
2023-03-02 15:13:12,903 WARN [runner.ScriptBindingsManager]: Custom field value type or classclass java.util.ArrayList 2023-03-02 15:13:12,904 WARN [runner.ScriptBindingsManager]: Group Values 0: Data Security 2023-03-02 15:13:12,904 WARN [runner.ScriptBindingsManager]: Group Values 1: ADEMO 2023-03-02 15:13:12,906 WARN [runner.ScriptBindingsManager]: ProductTeam Objects: Product Team(s) 2023-03-02 15:13:12,906 WARN [runner.ScriptBindingsManager]: Present Value for AWOLBP-2: Bar 2023-03-02 15:13:12,906 WARN [runner.ScriptBindingsManager]: Present Value for AWOLBP-2: Foo
Appreciate any direction!