Hi,
Is it possible to filter the shown values in a cascading select based on a single select selection?
for example
I have a field called Topic that is a single select with values 1, 2 and 3
I have a cascading select field called Product with parents:
A and child A1,B2,B3
B and child B1,B2,B3
C and child C1,C2,C3
I need to hide parent B and C when I select 1 from field Topic
When I select 2 from Topic I need to hide parents A and B
Thanks
For your requirement, you can try something 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 sampleList = getFieldById(fieldChanged)
def sampleListValue = sampleList.value.toString()
def sampleCascade = getFieldByName('Sample Cascade')
def filteredCascadeField = customFieldManager.getCustomFieldObject(sampleCascade.fieldId)
def availableConfig = filteredCascadeField.getRelevantConfig(issueContext)
def listCascadeOptions = optionsManager.getOptions(availableConfig)
def childField = getFieldById("${sampleCascade.fieldId}:1")
def childList = customFieldManager.getCustomFieldObject(childField.fieldId)
def msConfig = childList.getRelevantConfig(issueContext)
def childOptions = optionsManager.getOptions(msConfig)
def availableOptions
if (sampleListValue == '1') {
availableOptions = listCascadeOptions.findAll {it.value in ['A'] }.collectEntries {[(it.optionId.toString()) : it.value] }
} else if (sampleListValue == '2') {
availableOptions = listCascadeOptions.findAll {it.value in ['B'] }.collectEntries {[(it.optionId.toString()) : it.value] }
} else if (sampleListValue == '3') {
availableOptions = listCascadeOptions.findAll {it.value in ['C'] }.collectEntries {[(it.optionId.toString()) : it.value] }
}
sampleCascade.setFieldOptions(availableOptions)
sampleCascade.setFormValue([availableOptions, childOptions.optionId])
Please note that the sample working above is not 100% exact to your environment. Hence, you will need to make the required modifications.
The code above is for a Server-Side Behaviour, i.e. for the Single Select list that you want to use to filter the Cascading List.
This Server-Side Behaviour filters the Sample Cascade field when the value from the Sample List field is selected.
Below is a print screen of the Behaviour configuration:-
Also, I include a few test print screens for your reference:-
1. When I select option 1 from the Sample List, the Sample Cascade list is filtered to only option A and its child list will only show the options A1, A2 and A3, as shown in the print screens below:-
2. When I select option 2 from the Sample List, the Sample Cascade list is filtered to only option B, and its child list will only show the options B1, B2 and B3 as shown in the print screens below:-
3. Lastly, when I select option 3 from the Sample List, the Sample Cascade list is filtered to only option C, and its child list will only show the options C1, C2 and C3, as shown in the print screens below:-
I hope this helps to solve your question. :)
Thank you and Kind regards,
Ram
Hi Team,
If I select C1 from Child need a new select list field called Test to be enabled, Please help me with a Groovy script or by options.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_ ,
How to show only A1,B1,C1 child values in your example?
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I would assume that for A, you want A1, B, it's B1, and C, C1.
For this, you will have only to modify the code slightly:-
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 sampleList = getFieldById(fieldChanged)
def sampleListValue = sampleList.value.toString()
def sampleCascade = getFieldByName('Sample Cascade')
def filteredCascadeField = customFieldManager.getCustomFieldObject(sampleCascade.fieldId)
def availableConfig = filteredCascadeField.getRelevantConfig(issueContext)
def listCascadeOptions = optionsManager.getOptions(availableConfig)
def childField = getFieldById("${sampleCascade.fieldId}:1")
def childList = customFieldManager.getCustomFieldObject(childField.fieldId)
def msConfig = childList.getRelevantConfig(issueContext)
def childOptions = optionsManager.getOptions(msConfig)
def availableOptions
if (sampleListValue == '1') {
availableOptions = listCascadeOptions.findAll {it.value == 'A1' }.collectEntries {[(it.optionId.toString()) : it.value] }
} else if (sampleListValue == '2') {
availableOptions = listCascadeOptions.findAll {it.value == 'B1' }.collectEntries {[(it.optionId.toString()) : it.value] }
} else if (sampleListValue == '3') {
availableOptions = listCascadeOptions.findAll {it.value == 'C1' }.collectEntries {[(it.optionId.toString()) : it.value] }
}
sampleCascade.setFieldOptions(availableOptions)
sampleCascade.setFormValue([availableOptions, childOptions.optionId])
This should work for your requirement.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Team if c1 is selected from the child I need to display a new selectlist field called Test select list, Please help me with a script or option.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.