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.
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:-
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
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.
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:-
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.
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
Hello @Ram Kumar Aravindakshan _Adaptavist_ ,
Thank you so much for the response, it worked as expected.
Thanks,
R.Janaki
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.