I wanted to set a default value for the custom field cascading select list field based on another cascading select list field using script runner behaviors on the create screen.
When user selects
Field1 = A1, A2
then set default value for
Field2 = X1, X2
I wrote down behavior script not seems to be working
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import org.apache.log4j.Level
import org.apache.log4j.Logger
import com.atlassian.jira.issue.Issue
@BaseScript FieldBehaviours fieldBehaviours
// the cascading select field that you want to set
final fieldName = 'Release Focus'
// Parent value that you want to set
final parentValue = 'Experiences'
// child value that you want to set
final childValue = 'APIs'
def field = getFieldByName(fieldName)
def optionsManager = ComponentAccessor.optionsManager
def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issueContext.projectId, issueContext.issueTypeId).findByName(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 }
// the name of the custom field cascading field2
def cfield = getFieldByName("Driver")
Map mapValue = cfield.getValue() as Map
def value1 = mapValue.get(0).toString()
def value2 = mapValue.get(0).toString()
if(value1 == "Maintenance" && value2 == "Fix Pack"){
field.setFormValue([parentOption.optionId, childOption.optionId])
}