What script can I use to restrict the values on a cascade select field?

Julia
Contributor
November 10, 2021

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 

1 answer

1 vote
Peter-Dave Sheehan
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.
November 10, 2021

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")
}

Suggest an answer

Log in or Sign up to answer