Validate multi select customfield in transition

Wolfgang Fellner November 5, 2012

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?

2 answers

1 accepted

3 votes
Answer accepted
JamieA
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.
November 7, 2012

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.

JamieA
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.
November 7, 2012

You need to add a null check too as you will get null when there are no options set.

Wolfgang Fellner November 7, 2012

Thank you very much. That works :-)

JamesR November 29, 2012

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.

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 24, 2020

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")

Pranita Warik September 29, 2020

@JamieA 

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

 

@JamieA 

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.

1 vote
Nitram
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.
November 7, 2012

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
   }
}

JamieA
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.
November 7, 2012

Sorry to downvote but you have written javascript, whereas he is using groovy.

Suggest an answer

Log in or Sign up to answer