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

Use a Cascading Select List to Validate an Action on an Issue.

Features
Validators
Created 1 year ago, Updated 1 month(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.atlassian.jira.config.IssueTypeManager

// the name of the custom field
final customFieldName = 'CascadingSelect'

// the expected parent value of the Cascading Select custom field
final parentValue = 'AAA'

// the expected child value of the Cascading Select custom field
final childValue = 'A1'

// the name of the issue type we want to check
final issueTypeName = 'Task'

def issueType = ComponentAccessor.getComponent(IssueTypeManager).issueTypes.findByName(issueTypeName)
assert issueType: "Could not find issue type with name $issueTypeName"

// if the issue type is not the one we are looking for, return true
if (issue.issueType != issueType) {
    return true
}

def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)
assert customField: "Could not find custom field with name $customFieldName"

def selectedOptions = issue.getCustomFieldValue(customField) as Map

// in order to obtain the value you need, you will need to specify the option parent level.
// parent options do not have an ancestor, so the parent level is always 'null'.
// the selected child option has an ancestor and the parent level is always '1'.
// if there are is a third level of options, in order to obtain the selected value, it would be '2'
def parentOptionLevel = null
def childOptionLevel = '1'

def selectedParentValue = selectedOptions.get(parentOptionLevel).toString()
def selectedChildParentValue = selectedOptions.get(childOptionLevel).toString()

selectedParentValue == parentValue && selectedChildParentValue == childValue
Having an issue with this script?
Report it here