Checking values selected from a multi checkbox custom field

Mia
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.
June 12, 2013

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
Answer accepted
Mia
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.
June 12, 2013
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.

Hemanshu Sood July 30, 2018

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events