Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to make Cascading Drop-down child field mandatory only when parent has value?

Jira Dev February 18, 2025

Hello all, I need help in setting up a validation on Cascading drop-down custom field in a JIRA Data Center environment using ScriptRunner Behaviours. How to make a "child" part mandatory, but only if a "parent" has a value?

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
February 18, 2025

Hhi @Jira Dev

Welcome to the Community.

I have provided the exact answer to your requirement in this Community Post.

The solution provided in the link also uses ScriptRunner's Behaviour and performs a validation to ensure that both Parent and Child options are selected in the Cascade Select List.

I hope this helps answer your question. :-)

Let me know how it goes.

Thank you and Kind regards,
Ram 

Jira Dev February 18, 2025

Not all of my “parent” options have “child” values, so the script doesn’t work the way I need it to. It currently makes the “child” field mandatory for every “parent,” even when there are no child options available.

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
March 3, 2025

Hi @Jira Dev

Thank you for getting back and providing your feedback.

For your case, you must modify the sample code that I provided in the Community Post to something like this:-

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours
def sampleCascade = getFieldById(fieldChanged)
def sampleCascadeValue = sampleCascade.value as List
sampleCascade.clearError()

def customFieldManager = ComponentAccessor.customFieldManager
def optionsManager = ComponentAccessor.optionsManager

def customField = customFieldManager.getCustomFieldObjects(issueContext.projectId, issueContext.issueTypeId).findByName('Sample Cascade')

def fieldConfig = customField.getRelevantConfig(issueContext)

def options = optionsManager.getOptions(fieldConfig)

if (sampleCascadeValue) {
def parentOption = options.find { it.value == sampleCascadeValue.first() }
def childOption = parentOption?.childOptions

if (childOption.size() > 0 && sampleCascadeValue.size() < 2) {
sampleCascade.setError('Child List Must Be Selected')
}
}

Please note that the sample working code above is not 100% exact to your environment. Hence, you must make the required modifications.

The modification is required to ensure that the validation will only trigger when the Parent option selected from the Cascade Select List has Child option(s). If the Parent does not have any child options the validation will not trigger.

Below is a screenshot of the Behaviour configuration:-

behaviour_configuration.png

I am also including a couple of test screenshots for your reference:-

1. When the Cascading Select List has both Parent and Child options, the Validation error message is displayed as expected as shown in the screenshot below:-

test1.png

2. If the Cascading Select List only has options from the Parent List and none from the Child List, the error message is not displayed as expected as shown in the screenshot below:-

test2.png

I hope this helps to solve your question. :-)

Thank you and Kind regards,
Ram

 

Like Jira Dev likes this
TAGS
AUG Leaders

Atlassian Community Events