Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,464,959
Community Members
 
Community Events
176
Community Groups

Filter values from cascading select based on selection from other single select field

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

2 answers

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.

Hi @Peter Newton

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:-

behaviour_config.png

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:-

1.png2.png

 

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.png4.png

 

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:-

5.png6.png

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.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events