Show/Hide options from cascading select list

Arianna Fabbri August 12, 2015

Hi,

I need to add/remove options from cascading select list while creating a new issue based on the value selected in another field.

I think that the best way is to use Behaviour plugin => I will set the basic options that have to be shown everytime and then, based on the selection of another field, I add the additional options related to the specific selection.

 

Can anyone suggest me a way to implement this behaviour?

 

Thank you in advance

Regards

Arianna

4 answers

1 accepted

5 votes
Answer accepted
Kristian Walker _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.
October 26, 2015

Hi Ariana,

I have enclosed a code sample below which shows how you can use the Behaviours plugin provided by script runner to dynamically remove and set from a Select List field based on an option selected inside a check box field.

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor

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

// Get a pointer to my select list field
def selectList = getFieldByName("Demo Select List")

// Get a pointer to my check box field
FormField checkBox = getFieldByName("Check Box 1")

// Get access to the required custom field and options managers
def customField = customFieldManager.getCustomFieldObject(selectList.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)


// Get the checkbox option value as a String
def checkBoxVal = checkBox.getValue()

// Logic to do some actions depending on what check box value is selected
if (checkBoxVal == "A") {
    // define and set the required options when checkbox A is selected
    def optionsMap = options.findAll {
        it.value in ["A", "B"] // list of options you want to show
    }.collectEntries {
        [
                (it.optionId.toString()): it.value
        ]
    }
    selectList.setFieldOptions(optionsMap)
} else if (checkBoxVal == "B") {
    // define and set the required options when checkbox A is selected
    def optionsMap = options.findAll {
        it.value in ["C", "D", "E"] // list of options you want to show
    }.collectEntries {
        [
                (it.optionId.toString()): it.value
        ]
    }
   selectList.setFieldOptions(optionsMap)
}

 

I hope this helps.

Kristian

Arianna Fabbri November 17, 2015

Thank you very much!! Arianna

Arianna Fabbri November 14, 2016

Hi @Kristian Walker (Adaptavist),

any news about cascading select list?

 

I'm trying this behaviour script:

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Level
import com.atlassian.jira.issue.customfields.option.Option
log.setLevel(org.apache.log4j.Level.DEBUG)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
FormField IssueSource = getFieldById(getFieldChanged())
log.debug "Modifica rilevata: " + IssueSource
String issuesourcevalue = (String) IssueSource.getValue()
// Get a pointer to Department/Job Title select list
FormField deptJobTitleList = getFieldByName ("Department/Job Title")
def deptJobTitleSelectAA = customFieldManager.getCustomFieldObject(deptJobTitleList.getFieldId())
def deptJobTitleSelectOth = customFieldManager.getCustomFieldObject(deptJobTitleList.getFieldId())
def configAA = deptJobTitleSelectAA.getRelevantConfig(getIssueContext())
def configOth = deptJobTitleSelectOth.getRelevantConfig(getIssueContext())
def optionsAA = optionsManager.getOptions(configAA)
def optionsOth = optionsManager.getOptions(configOth)
Map<String,Object> optionsMapAA
Map<String,Object> optionsMapOth
optionsMapAA = optionsAA.findAll {
    it.value in ["None", "A", "B", "C"] 
}.collectEntries {
    [
        (it.optionId.toString()): it.value
    ]
}
log.debug "opt map: " + optionsMapAA
optionsMapOth = optionsOth.findAll {
    it.value in ["None", "D", "E", "F", "G","H","I","L","M","N","O","P"]
}.collectEntries {
    [
        (it.optionId.toString()): it.value
    ]
}
log.debug "opt map: " + optionsMapOth
// Get a pointer to Company select list
FormField Company = getFieldById("customfield_14600") 
if(issuesourcevalue != null && Company.getValue() != null){
    if (issuesourcevalue.contains("1") && Company.getValue().equals("Headquarters")){
        deptJobTitleList.setFieldOptions(optionsMapAA)  
    }else{
        deptJobTitleList.setFieldOptions(optionsMapOth) 
    }
}

When I open new issue create screen and change the value of the field to which the script is linked to, I get, only the first type, the correct result in the cascading select.

As soon as I change again the value, the first level of the cascading select is correctly changed but the second level is empty.

 

Why at the first value selection both level of the select are correctly loaded and on the following changes the second level is no longer loaded?

 

Thank you in advance for your help

 

Adam Gaudry December 29, 2017

Hi Kristian

I have created the following script based on your advice, trying to get the choice of one select list to alter the options present on another. But nothing seems to happen when I use this code. Can you possibly advise?

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor

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

// Point towards Change Result Reason custom field list
def selectList = getFieldById("customfield_15601")

// Point towards Change Result custom field list
def checkBox = getFieldById("customfield_15600")

// Get access to the required custom field and options managers
def customField = customFieldManager.getCustomFieldObject(selectList.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)

// Get the checkbox option value as a String
def checkBoxVal = checkBox.getValue()

// Logic to do some actions depending on what check box value is selected
if (checkBoxVal == "Successful") {
// define and set the required options when checkbox A is selected
def optionsMap = options.findAll {
it.value in ["Implemented Successfully"] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectList.setFieldOptions(optionsMap)
} else if (checkBoxVal == "Partially Successful") {
// define and set the required options when checkbox A is selected
def optionsMap = options.findAll {
it.value in ["Bug", "Compatibility Issue", "Configuration Issue", "Deployment Failure", "Did Not Address Reason for Change", "Human Error", "Infrastructure Failure", "Incomplete CHG", "Incomplete documentation", "Management/Business Request", "Methodology not understood or tested", "Other", "Successful", "Testing Failure"] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectList.setFieldOptions(optionsMap)
} else if (checkBoxVal == "Unsuccessful") {
// define and set the required options when checkbox A is selected
def optionsMap = options.findAll {
it.value in ["Bug", "Compatibility Issue", "Configuration Issue", "Deployment Failure", "Did Not Address Reason for Change", "Human Error", "Infrastructure Failure", "Incomplete CHG", "Incomplete documentation", "Management/Business Request", "Methodology not understood or tested", "Other", "Successful", "Testing Failure"] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectList.setFieldOptions(optionsMap)
}
0 votes
Varun Nelluri May 8, 2020

@Arianna Fabbri , Do you have any luck with Cascading field values display based on check list. Thanks

Erick Johanson July 31, 2020

the same question)

0 votes
Kristian Walker _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.
October 9, 2015

Hi Arriana,

 

I have been looking into this and it appears that setting values in Cascading Select fields is currently not fully supported.

The way to get around this would be to implement two single select lists and then use the OptionsManager() to dynamically add and remove values.  An example of how this can be done is shown in the answer located here.

Thanks


Kristian

JessicaB December 7, 2017

Kristian - has this been resolved with new updates? If this works for a select list shouldn't it be easy to adapt for a cascading select? Forgive me if I'm oversimplifying.

0 votes
Guilherme Nogueira
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 19, 2015

Maybe you can use javascript/behavior instead

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events