Forums

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

how to validate a multi select list with simple scripted validator for a default value?

hemanth acharya January 21, 2015

Hi All,

I have a scenario:

-> There are two fields, one is a 'Text field' and another is a 'Multi select list', these two fields appear only during a transition.

-> Multi select list field is always mandatory and the text field should be made mandatory based on the value in selected in the list. Also, the multi select list has a value "None" which is by default in the Jira

-> I have written two scripted validator for these:

((cfValues["Test multi"]*.value.contains("Value 1") || cfValues["Test multi"]*.value.contains("Value 2")) && cfValues['Text field'])  â€” LHS

||  ---- OR


(!cfValues["Test multi"] || cfValues["Test multi"]*.value.contains("Value 3")) ---- RHS

Basically, the above defines: If value 1 and value 2 from the list are chosen and the 'Text field' is empty then show error that this field is required. If Value 3 is chosen then the 'Text field' is not mandatory.

But the problem here is, '!cfValues["Test multi"]' condition doesnt seem to work at all. 

I have tried all the combination now viz cfValues["Test multi"] != null and cfValues["Test multi"]?.value != null etc. Nothing seem to work, Am I doing anything trivial? Please suggest.

Thanks,

Hemanth

2 answers

2 votes
Cesare Jacopo Corzani
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 29, 2015

You can get the custom fields by using:

def multiSelectField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Test multi");
def options = issue.getCustomFieldValue(multiSelectField) as List<Option>
 
if (!options){
// No element is selected
}
 
"Value 1" in options*.value // True if "Value 1" is in the list
 
options*.value.containsAll(['Value 1','Value 2']) // True if both of the elements are in the options list

This is example is related to the multi select field.

hemanth acharya January 29, 2015

@Cesare Jacopo Corzani , does this go in "simple scripted validator" ? Can you tell me what is wrong in the way I have used? Thanks

Cesare Jacopo Corzani
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2015

This page answers your previous question: https://jamieechlin.atlassian.net/wiki/display/GRV/Validators

hemanth acharya January 30, 2015

you mean to say using "cfValues['Text field'])" will retrieve value in the field from the database?

Cesare Jacopo Corzani
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2015

I deleted my previous comment because it was confusing. cfValues should work too, I have a feeling cfValues is only available to the "Condition" and "Additional Actions" block, and not when using a custom script. Is it working now?

hemanth acharya January 30, 2015

yes, I tried cfValues in "simple scripted validator" and not in custom validator. I edited my question, the real problem here in LHS || RHS doesn't work. Individually LHS and RHS works. I am not sure what makes it fail when I combine them. Any idea? Thanks

0 votes
hemanth acharya January 22, 2015

@Jamie Echlin [Adaptavist] Could you please help me with this? Thanks

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira product discovery, jpd premium, product management, idea management, product discovery, jira premium, product planning, atlassian community, product development, roadmap planning, product prioritization, feature management

Introducing Jira Product Discovery Premium ✨

Jira Product Discovery Premium is now available! Get more visibility, control, and support to build products at scale.

Learn more
AUG Leaders

Atlassian Community Events