Checkbox field error

Certified Associate Developer

I've been trying to implement a checkbox field but keep receiving an error. I can select either choice. I can select nothing. But if I select both choices, I get the following error: 

Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function a!checkboxField [line 638]: A checkbox component [label=""] has an invalid value for "value". All selected values must be present in the choiceValues array, but value was Fatality; Serious Injury and choiceValues was Fatality; Serious Injury.

For reference, this is the code I am using:

What am I doing wrong? 

  Discussion posts and replies are publicly visible

  • 0
    Certified Senior Developer

    Hi  

    The issue is because you are trying to save multiple values in a single field. If you want to select multiple values the value must be a type of array.

    a!localVariables(
      local!data:{},
      a!checkboxField(
        label:"Skills",
        choiceLabels: {"C","C++",".net","java","appian"},
        choiceValues: {"C","C++",".net","java","appian"},
        value: local!data,
        saveInto: local!data
      )
    )

  • 0
    Certified Lead Developer

    Storing multiple values in one field is a dangerous design decision. If this is what you want/need, you can use something like this:

    a!localVariables(
      local!boxValue,
      a!checkboxField(
        choiceLabels: {"Option 1", "Option 2"},
        choiceValues: {1, 2}, /* Integers here */
        label: "Checkboxes",
        labelPosition: "ABOVE",
        saveInto: a!save(
          target: local!boxValue,
          value: joinarray(a!defaultValue(save!value, {}), ";")
        ),
        value: if(
          a!isNullOrEmpty(local!boxValue),
          null,
          tointeger(split(local!boxValue, ";")) /* Integers here */
        ),
        validations: {}
      )
    )

    An alternative is, to store the values in JSON format using toJson() and fromJson().