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

Julia 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
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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