Hello everybody!
I need your help in figuring how to filter through a cascading select list and display it based on values selected from another field.
I have the following setup:
Select List (Single Choice) CF called Software Version with 2 Values: CGD and NGD
Select List (cascading) CF called Interface Request with the following options:
Parent A with options A1, A2, A3
Parent B with options B1, B2, B3
Parent C with options C1, C2, C3
I'm looking to filter through the cascading list options using a Scriptrunner behaviour to achieve the following cascading list options:
Software Version CGD is selected -> Interface Request options available: Parent A with all children and Parent B with children B1, B2
Software version NGD selected -> Interface Request options available: Parent B with B3 child and Parent C with all children.
I've been following the below Community post: https://community.atlassian.com/t5/Jira-Software-questions/Filter-values-from-cascading-select-based-on-selection-from/qaq-p/1994209
but it seems that even if I simply try to set only the Parent values I get a typecheck error on interfaceRequestField.setFieldOptions(availableOptions) :
[Static type checking] - Cannot call com.onresolve.jira.groovy.user.FormField#setFieldOptions(java.util.Map<?, java.lang.String>) with arguments [java.util.Map<java.lang.Object, java.lang.Object>]
Currently, the script looks like this:
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def customFieldManager = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager
def appVersion = getFieldById(fieldChanged).value.toString()
def interfaceRequestField = getFieldByName('Interface Request')
def filteredInterfaceRequestField = customFieldManager.getCustomFieldObject(interfaceRequestField.fieldId)
def availableConfig = filteredInterfaceRequestField.getRelevantConfig(issueContext)
def listCascadeOptions = optionsManager.getOptions(availableConfig)
def childField = getFieldById("${interfaceRequestField.fieldId}:1")
def childList = customFieldManager.getCustomFieldObject(childField.fieldId)
def msConfig = childList.getRelevantConfig(issueContext)
def childOptions = optionsManager.getOptions(msConfig)
def availableOptions
if (appVersion == 'CGD'){
availableOptions = listCascadeOptions.findAll { it.value == 'Employee SSO' }.collectEntries { [(it.optionId.toString()) : it.value] }
} else {
availableOptions = listCascadeOptions.findAll{ it.value == 'Admin SSO'}.collectEntries { [(it.optionId.toString()) : it.value]
}
}
interfaceRequestField.setFieldOptions(availableOptions)
interfaceRequestField.setFormValue([availableOptions, childOptions.optionId])
Am I really overcomplicating my existence with cascading fields instead of using 2 separate single select fields that get filtered based on selected values? I've been able to successfully implement behaviours that filter through single select lists based on issue types. And I assume that filtering based on a CF value is not much of a difference.
Thanks a lot in advance!