In Jira how to control the values of a multi select field based on value selected on another field

prakash ganeshan April 4, 2019

I have requirement, request your help here:

I have two custom fields ApplicationName (single select) & Componentname (multi select).  Now based on the value selected in Application field values of Component field should change.

With the help of this post, thanks for this post - https://community.atlassian.com/t5/Marketplace-Apps-questions/Show-Hide-options-from-cascading-select-list/qaq-p/260685

I am able to come up with the below script which works perfectly but I need to select any value in the "Component" field for the changes to reflect.  Is there a way when the Application field is selected and Component field updates automatically without being selecting a value in Component field?

Thanks in advance.

 

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

def appField = getFieldByName("ApplicationName")
def selectList = getFieldByName("ComponentName")

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

def customField = customFieldManager.getCustomFieldObject(selectList.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)

def appselectedOption= appField.getValue() as String

if(appselectedOption.contains("App")){
def optionsMap = options.findAll {
it.value in ["UI", "Web"] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectList.setFieldOptions(optionsMap)
}
else if(appselectedOption.contains("DB")){
def optionsMap1 = options.findAll {
it.value in ["Oracle", "SQL"] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectList.setFieldOptions(optionsMap1)
}

 

0 answers

Suggest an answer

Log in or Sign up to answer