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?
You could just change this:
def options = optionsManager.getOptions(config).findAll{!it.disabled}
You beat me to it Peter, but that was what I found as well!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I was able to find them doing something like this:
options.findAll {it.getDisabled() == false}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.