Skip to main content
Example scripts
arrow icon
To homepage
Jira
Data centre icon
Data Center

Set a Default Option on a Cascading Select List

Features
Behaviours
Created 2 year(s) ago, Updated 25 day(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
Jira (8.0 - 8.14)
compatibility bullet
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