Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to build a three dependent select lists

sam siu March 6, 2018

Would anyone mind to give some suggestions on how to make a dependent select list?

Or if there is any work around without use plugins.

I mean if there is 3 list: A,B and C. The options of B depend on what we choose in list A.

The cascading list only allows two select list.

Can I use two cascading A B and B C to make the relationship between A,B and C? 

Thanks

         

1 answer

1 accepted

0 votes
Answer accepted
Alex Christensen
Community Champion
March 6, 2018

I know you said no plugins, but...

If you're on Jira Server or Data Center, you can do this with the Behaviours module of ScriptRunner. If that's an option for you, I suggest looking into that.

An option in default Jira would be to use a single-select list with all of the possible A, B, and C combinations as single values in this field, but if you have a lot of values/combinations, it might get pretty messy or you might have A LOT of values in the field.

sam siu March 6, 2018

Hi Alex,

Thanks for your reply!

I tried the Behaviours module but it cannot dynamic change the options in a select list from A,B,C to D,E,F.

I can only select a value for select list based on other custom field value.

Alex Christensen
Community Champion
March 7, 2018

I believe it's possible to set the options available in a select list field using the Behaviors add-on. In the quick reference guide, there is a method for doing this:

Method

formField.setFieldOptions(Iterable

 Example

formField.setFormValue(options.findAll {it.value in ['foo', 'bar']})

Here's a quick example that might cover your requirements.

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()

def fieldA = getFieldByName("Field A").getValue()
def fieldB = getFieldByName("Field B").getValue()

def fieldBObject = customFieldManager.getCustomFieldObjectByName("Field B")
def fieldBConfig = fieldBObject.getRelevantConfig(issue)
def fieldBOptions = optionsManager.getOptions(fieldBConfig)

if (fieldA.equals("Some value")) {
fieldB.setFieldOptions(fieldBOptions.findAll {it.value in ['value a', 'value b']})
}
else if (fieldA.equals("Some OTHER value") {
fieldB.setFieldOptions(fieldBOptions.findAll {it.value in ['value c', 'value d']})
}

I haven't done any troubleshooting on this, so the code might need a little work. You would need to add another script to the same Behaviour based on what is chosen for Field B to also update the options available for Field C.

Hope this helps or at least points you in the right direction!

sam siu March 8, 2018

Thanks!

It works

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events