I have a Cascade Select custom field with the id "19000" and want to restrict the visible values depending on the issue type selected.
I cannot figure out which script to use... any help would be appreciated
This should be a good place to start: https://library.adaptavist.com/entity/dynamic-select
Of course, this is for basing one single select on another, not adjusting the list in a cascading select. But it's virtually the same.
Here is a sample script:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
def optionsManager = ComponentAccessor.optionsManager
def csFieldName = 'Root Cause'
def csFieldId = 'customfield_19000'
def csFormField = getFieldByName(csFieldName) // or getFieldById(csFieldId)
def issueType = issueContext.issueType.name
def issueTypeOptionMap = [
IssueType1:['Option1', 'Option2'],
IssueType2:['Option3', 'Option4']
]
def allowedOptionsValues = issueTypeOptionMap[issueType]
if(allowedOptionsValues){
def csCf = ComponentAccessor.customFieldManager.getCustomFieldObject(csFormField.fieldId)
def config = csCf.getRelevantConfig(issueContext)
def options = optionsManager.getOptions(config)
Map allowedOptions = options.findAll{it.value in allowedOptionsValues}.inject(["":'None']){ Map map, Option opt->
map[opt.optionId as String] = opt.value
map
}
csFormField.setFieldOptions(allowedOptions)
} else {
csFormField.setHelpText("No valid options for this issue type:$issueType")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.