Example scripts
To homepage
Jira

Set a Default Option on a Cascading Select List
App in script

ScriptRunner For Jira
by Adaptavist
Compatibility

Jira (8.0 - 8.14)

ScriptRunner For Jira (6.18.0)
Language |
groovy
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
// the cascading select field that you want to set
final  fieldName = 'Cascading Select'
// parent value that you want to select
final  parentValue = 'AAA'
// child value that you want to select
final  childValue = 'A1'
def field = getFieldByName(fieldName)
def optionsManager = ComponentAccessor.optionsManager
def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issueContext.projectId, issueContext.issueTypeId).findByName(fieldName)
assert customField : "Could not find custom field with name $fieldName"
def fieldConfig = customField.getRelevantConfig(issueContext)
def options = optionsManager.getOptions(fieldConfig)
// find the Cascading Select options with those values
def parentOption = options.find { it.value == parentValue }
def childOption = parentOption?.childOptions?.find { it.value == childValue }
assert parentOption && childOption : 'One ore more of the given option values are not available'
field.setFormValue([parentOption.optionId, childOption.optionId])
Having an issue with this script?
Report it here