I have to fields on a form: "Account type" and "Management preference". Both are single-select lists. I'm trying to limit the options of "Account type" based on the selection of "Management preference". Basically if the "Management preference" is "Unmanaged", then there should be only 2 options available, otherwise, you could choose anything from "Account type".
This is the script I wrote
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
def managamenetPreferenceField = getFieldById(getFieldChanged())
def accountTypeField = getFieldById("customfield_13802")
def optionsManager = ComponentAccessor.getComponent(OptionsManager)
def accountTypecustomField = customFieldManager.getCustomFieldObject("customfield_13802")
def config = accountTypecustomField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def managementPreference = managamenetPreferenceField.getValue()
if (managamenetPreferenceField != null) {
if (managementPreference == "Unmanaged") {
def unamanagedOptions = ['Playground - Individual', 'Playground - Shared']
accountTypeField.setFieldOptions(options.findAll {it.value in unamanagedOptions})
if (!(accountTypeField.getValue() in unamanagedOptions)) {
accountTypeField.setFormValue('Playground - Individual')
}
} else {
accountTypeField.setFieldOptions(options)
}
}
The problem comes, that the "optionsManager.getOptions(config)" methd returns even the disabled options, which is not ok. Is there a way (through the code) I could filter out the enabled options?