Filter through Cascading List options based on different Select List (single choice)

Gabriel Udvar March 26, 2024

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!

1 answer

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 26, 2024

Hi @Gabriel Udvar

The solution I provided in the link you mentioned in your description should already work for your requirements.

In regards to the error you are encountering, please share the versions of Jira and ScriptRunner you are currently using. 

Also, if you could share a screenshot of your Behaviour editor, in which you are encountering the error message it would be helpful.

I am looking forward to your feedback.

Thank you and Kind regards,

Ram

Gabriel Udvar March 27, 2024

Hi @Ram Kumar Aravindakshan _Adaptavist_ ,

Thanks for the reply!

Indeed the solution does work. And it filters through the Parent options correctly. 

I am running a Jira 9.4.9 instance and Scriptrunner 8.24.0 (recently upgraded from 8.6.0). The error is present on both SR versions. 

Interface Request Behaviour.JPG

I added a snip of the Editor and the error that it throws. 

 

I'd need some more help on filtering through the child options. 

For parent option 'File Transfer (SFTP/FTP)' I have a list of 9 child options. I'd need to display 4 of these if appVersion = 'CGD' and a different set if appVersion = 'NGD'.

Would this be possible? Or should I create separate Parent options for each of them?

 

Thanks again for all your help. Really appreciate it!

 

Regards,

Gabriel

Suggest an answer

Log in or Sign up to answer