I have a multi-select field that I am hoping to have add values as options via a behavior.
The thought is that the values in the multi-select will:
- Get the value(s) selected from the issue it is being loaded on
- Iterate through the issues to isolate individual values
- Compare the values against a map (key = Multi-Select, value = project ID)
- Use the project ID to get applicable context values
- Add context values to a final list of options
- Present the user with the final list of options based on their multi-select field selections
I'm having some issues with the part where I would iterate through the multi select values. I am able to get the values, but when trying to compare them to the map it is never matching.
Here is 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,
'Bar':16901
]
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
log.warn "$i matched with ${projectContextMap.value}"
}
}
Here are the logs where I am seeing the value identified, but not matching a key in the list:
2023-03-02 15:13:12,906 WARN [runner.ScriptBindingsManager]: Present Value for AWOLBP-2: Data Security 2023-03-02 15:13:12,906 WARN [runner.ScriptBindingsManager]: Present Value for AWOLBP-2: ADEMO
Any guidance on how to get that i value compared with a key would be super helpful!