Behavior script for Multi check box field

Hemanshu Sood July 31, 2018

Hi, I have written a behavior script to authenticate options selected in a Multi Check box field , on the create issue screen. It does not seem to be working:

 

 

 

FormField testCheck = getFieldById ("customfield_23350") // id for Test Check Box Field
FormField tType = getFieldById ("customfield_22150") // id for Field 1
FormField type = getFieldById ("customfield_15551") // Field 2

List <String> checkList = testCheck.getValue()

switch(checkList)

{
case ['36000']: // Id of check box option 1
tType.setHidden(true);
break


case ['36000','36001']: //Ids of 2 options in the check box field
type.setHidden(true);
break

}

 

Please help

1 answer

1 accepted

1 vote
Answer accepted
Mark Markov
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.
July 31, 2018

Hello @Hemanshu Sood

The thing is that switch operator dont work with ArrayList. In your example better use IF statement. And remeber that when checkbox contains only one option selected, it will be return String object, not List<String>. So in this case better not use static define, use dynamic 

def checkList = testCheck.getValue()

But if you really need switch for some reason, you need cast getValue as string and only after use switch, here is script.

FormField testCheck = getFieldById ("customfield_23350") // id for Test Check Box Field
FormField tType = getFieldById ("customfield_22150") // id for Field 1
FormField type = getFieldById ("customfield_15551") // Field 2

def checkList = testCheck.getValue().toString()

switch(checkList)

{
case '36000': // Id of check box option 1
tType.setHidden(true);
break


case '[36000, 36001]': //Ids of 2 options in the check box field
type.setHidden(true);
break

}
Hemanshu Sood July 31, 2018

Bingo, It works @Mark Markov , The mistake i did :

I was using the Option ID of the check box values(36000, 36001) instead of the exact option names. Rookie error.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events