Forums

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

Need to make second value mandatory in Cascade field select list

janaki December 26, 2023

Hello,

 

We have 10 cascade fields during issue creation, and we need to make the second field value mandatory for all 10 cascades using a single validator. Currently, we can achieve this with a scripted validator or JMWE validator for one field at a time. How can we enforce the requirement for the second field value across all 10 cascade fields using a single validator? Our Jira instance utilizes ScriptRunner and JMWE addons.

1 answer

1 accepted

2 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
December 27, 2023

Hi @janaki

For your requirement, you need to use ScriptRunner's Custom Script validator, and you will need to modify your Validation code to:-

import com.opensymphony.workflow.InvalidInputException

def cascadeFieldNames = ['Sample Cascade', 'Hardware Cascade']

cascadeFieldNames.each {
def cascadeFieldValue = issue.getCustomFieldValue(it) as Map

if (cascadeFieldValue && !cascadeFieldValue['1']) {
throw new InvalidInputException("${it}", 'Both Cascading Options Must Be selected')
}
}

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

If you observe the code above, I have listed the names of 2 cascading fields in the cascadeFieldNames list for this example. In your case, you must add the names of all the 10 cascading fields you want to validate into the cascadeFieldNames list.

In my environment, I have added the validation to the Create transition. You will need to set it according to your requirements.

Below is a screenshot of the Validation configuration:-

configuration.png

Below are a couple of test screenshots for your reference:-

1. Create a new issue. By default, no value is set to the Cascading List

test1.png

 

2. Set the values for the Cascading List. In the example below, only the parent value has been set for the Sample Cascade Field, and both values have been set for the Hardware Cascade field.test2.png

3. When the create button is clicked, the validator error message is returned since only the parent value from the Sample Cascade field has been set, as shown in the screenshot below:-

test3.png

4. The test is repeated once again; this time, both parent and child values have been set for the Sample Cascade, but only the parent value has been set for the Hardware Cascade field; the validation error message will display the error on the Hardware Cascade field.

test4.png

 

Note: The validation will be ignored if no value has been set for both Parent and Child of the Cascading list.

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

Thank you and Kind regards,
Ram

 

 

janaki December 27, 2023

Hello @Ram Kumar Aravindakshan _Adaptavist_ ,

 

Thank you so much for the response, it worked as expected.

 

Thanks,

R.Janaki

Suggest an answer

Log in or Sign up to answer