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

1 vote
Accepted answer
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.

HI, can you please share the updated script for multi check box field

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,709 views 3 11
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