Checking values selected from a multi checkbox custom field

I'm in the process of using the Behaviours plugin to create a custom form based on choices made the user. For example if they select one particular option (or that option and others) two text fields will appear for user entry.

I'm not sure if I am attempting to do this correctly or not, but I've spent ages trying to find a solution with zero luck.

I intend to use a switch statement to check each ID in the custom field. However, for the life of me I can't get a list to work which will store the IDs of the multi checkbox field to use as the cases for the switch. (NB: I haven't finished writing all the cases for the switch, and won't until I have the few cases there actually working).

I've gone through so many different variations that haven't work, I didn't save them all, so I have no code for reference in regards to list creation. All I have is below, the gap being for where the list should be declared (or something similar which will work).

FormField fAccess = getFieldByName("Access Details")
FormField fDrive = getFieldByName("Drive mappings required")
FormField fEmail = getFieldByName("Email groups required")



switch (values) {
  case ['11205']:
        fDrive.setHidden(false)
  fEmail.setHidden(false)
        break
        case ['11203', '11204', '11205', '11206', '11207', '11208']:
        fDrive.setHidden(false)
  fEmail.setHidden(false)
        break
        case ['11203', '11204', '11205', '11206', '11207']:
        fDrive.setHidden(false)
  fEmail.setHidden(false)
        break
        case ['11203', '11204', '11205', '11206']:
        fDrive.setHidden(false)
  fEmail.setHidden(false)
        break
        case ['11203', '11204', '11205']:
        fDrive.setHidden(false)
  fEmail.setHidden(false)
        break
        case ['11203', '11205']:
        fDrive.setHidden(false)
  fEmail.setHidden(false)
        break
        case ['11204', '11205', '11206', '11207', '11208']:
        fDrive.setHidden(false)
  fEmail.setHidden(false)
        break
        case ['11205', '11206', '11207', '11208']:
        fDrive.setHidden(false)
  fEmail.setHidden(false)
        break
        default:
        fDrive.setHidden(true)
  fEmail.setHidden(true)
        break
}

1 answer

1 accepted

FormField fAccess = getFieldByName("Access Details")
FormField fDrive = getFieldByName("Drive mappings required")
FormField fEmail = getFieldByName("Email groups required")
FormField fInf = getFieldByName("Information")
FormField fAlloc = getFieldByName("Allocation")

String Acc = (String) fAccess.getFormValue()
List<String> AccList = Acc.replaceAll(" ", "").minus("[").minus("]").split(",")

boolean networkAccessChecked = false
boolean corporateSiteChecked = false
for ( String i in AccList )
{
 if (i == "11205") {
  networkAccessChecked = true
 }
 if (i == "11207") {
  corporateSiteChecked = true
 }
}

if (networkAccessChecked) {
 fDrive.setHidden(false)
 fEmail.setHidden(false)
} else {
 fDrive.setHidden(true)
 fEmail.setHidden(true)
}

if (corporateSiteChecked) {
 fInf.setHidden(false)
 fAlloc.setHidden(false)
} else {
 fInf.setHidden(true)
 fAlloc.setHidden(true)
}

Nevermind, I finally got it to work and instead went for the much neater for loop over a switch.

Code above for any interested.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Marketplace Apps

Three tips for boosting your board's efficiency with Story Maps

Trello is one of the most effective tools for driving your sprints. It's customizable for every Agile team and product owners and Scrum masters (SM) love it. However, Agile teams often struggle with:...

830 views 2 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you