I would like to validate the selected option(s) of a multi select customfield in order to check if an other field is filled or not.
I already do this for select lists using a simple scripted validator (groovy script runner plugin):
if ( cfValues['some select list'].value == "some value") { if ( !cfValues['some dependent customfield'] ) {false} else {true} } else {true}
How does the script have to look like when using a multi select list instead of a select list?
You want to see if your multiselect contains some option value? It should return a List of Options, so you could use:
cfValues["Some Multiselect"]*.value.contains("Some value")
Note spread-dot operator to convert list of Options to list of Strings.
Note that if you had tagged your question you might get better answers.
You need to add a null check too as you will get null when there are no options set.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jamie, it seems that -- more often than not -- whenever I have a pressing question, your proposed solutions are the ones that save me (even when I'm not the one posting the question).
Thanks again and again and again.
Have a great weekend.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @JamieA my script is not working don't know..not running
I have multi select field having value Please Select, Dev/QA and Stage . User wants error when someone selected Please Select value , so insert this validator ... In my instance Environment field are some many more than 6-7. I used this script giving error for all values
cfValues["Enviornment"]*.value.contains("Dev/QA") || cfValues["Enviornment"]*.value.contains("Stage")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This des not work for checkboxes
cfValues["Some Multiselect"]*.value.contains("Some value")
It only validates the first value in checkbox.
I have a checkbox with values (Invoice,Approval, and so on)
It validates for .value.contains("Invoice") perfectly but not for
.value.contains("Approval") or any other value
Kindly help
My bad. While I was validating with the value "Approval", the actual value in the customfieldoption was "Approval Mail". On putting this value, its working perfect.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Wolf,
You need to add a "For" condition before the if else condition, since it is multi select, you need to take the options and you need to check whether the option is selected. Then you can have your logic. For eg
for(var i=0;i<oSelect.options.length;i++){ if(oSelect.options[i].selected){ Have your logic } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry to downvote but you have written javascript, whereas he is using groovy.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.