Checkbox value storage (multiple) and retrieval in read-only

It seems this question keeps poping up. But I ll keep it simple:

1. What is the best way to store checkbox values, when multiple choices are selected?

2. Is it possible to show such record on a read only checkbox?

I also checked Checkbox Component - Appian 21.2, but I could not find the information I am looking for.

I also tried changing the DB and CDT from integer to varchar/text.

Additional topics I looked at:

Appian Community

Appian Community

Appian Community

Appian Community

Kind regards,

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Senior Developer

    Hi,

    For question 1, when you select multiple values then it will be saved as colon separated values in db. if you query this value from database , then you would need to again convert into list of values .

    for Question 2. You can use Disabled parameter.

  • Thanks.

    I get what you wrote as I pasted:

    however I am getting this error.

  • a!checkboxField(
      label: "I need:",
      labelPosition: "ABOVE",
      choiceLabels: {"Travel tickets", "Hotel reservation", "Event fee", "Advance"},
      choiceValues: {"Travel tickets", "Hotel reservation", "Event fee", "Advance"},
      value: ri!record.additionalrequests,
      saveInto: ri!record.additionalrequests,
      validations: {}
    )

  • Try converting this to your needs

    a!localVariables(
      local!selectedOptions,
      {
        a!checkboxField(
          label: "Checkboxes",
          labelPosition: "ABOVE",
          choiceLabels: {"Option 1", "Option 2", "Option 3", "Option 4"},
          choiceValues: {"Option 1", "Option 2", "Option 3", "Option 4"},
          value: if(
            a!isNullOrEmpty(local!selectedOptions),
            {},
            split(local!selectedOptions, "#")
          ),
          saveInto: {
            a!save(
              local!selectedOptions,
              joinarray(save!value,"#")
            )
          },
          validations: {}
        ),
        a!paragraphField(
          value: local!selectedOptions,
        )
      }
    )

  • Thank you Sir, that worked. I am correctly displaying in on the next read only interface.

    There was an error, if I checked some options and then unchecked everything, so I had to slightly fix it.

    I used the following code:

    a!checkboxField(
      label: "I need:",
      labelPosition: "ABOVE",
      choiceLabels: {"Travel tickets", "Hotel reservation", "Event fee", "Advance"},
      choiceValues: {"Travel tickets", "Hotel reservation", "Event fee", "Advance"},
      value: if(
        a!isNullOrEmpty(ri!record.additionalrequests),
        {},
        split(ri!record.additionalrequests, "#")
      ),
      saveInto: a!save(ri!record.additionalrequests,if(isnull(save!value), save!value, joinarray(save!value,"#"))),
      validations: {}
    )

    How would I go about the other way, saving it in tables of a database?

    Can a single checkbox be split onto 4 collums in a database? In essence if you had 4 x checkbox, with a single checkbox and you would save them each of them in a single collumn?

  • +1
    Certified Lead Developer
    in reply to ajhick

    I see you're converting the values to/from a single String.  I'd strongly suggest, instead of using a bespoke format (joining by an arbitrary character '#' then splitting by the same), you simply make use of the built-in JSON functions and store the resulting string as JSON, since JSON has built-in routines to cleanly handle this in varieties of cases.

    e.g.

    a!localVariables(
      local!selectedOptions: a!toJson({}),
      {
        a!checkboxField(
          label: "Checkboxes",
          labelPosition: "ABOVE",
          choiceLabels: {"Option 1", "Option 2", "Option 3", "Option 4"},
          choiceValues: {"Option 1", "Option 2", "Option 3", "Option 4"},
          value: a!fromJson(local!selectedOptions),
          saveInto: {
            a!save(
              local!selectedOptions,
              a!toJson(a!defaultValue(save!value, {}))
            )
          },
          validations: {}
        ),
        
        a!paragraphField(
          label: "DEBUG",
          value: local!selectedOptions,
          disabled: true()
        )
      }
    )

Reply
  • +1
    Certified Lead Developer
    in reply to ajhick

    I see you're converting the values to/from a single String.  I'd strongly suggest, instead of using a bespoke format (joining by an arbitrary character '#' then splitting by the same), you simply make use of the built-in JSON functions and store the resulting string as JSON, since JSON has built-in routines to cleanly handle this in varieties of cases.

    e.g.

    a!localVariables(
      local!selectedOptions: a!toJson({}),
      {
        a!checkboxField(
          label: "Checkboxes",
          labelPosition: "ABOVE",
          choiceLabels: {"Option 1", "Option 2", "Option 3", "Option 4"},
          choiceValues: {"Option 1", "Option 2", "Option 3", "Option 4"},
          value: a!fromJson(local!selectedOptions),
          saveInto: {
            a!save(
              local!selectedOptions,
              a!toJson(a!defaultValue(save!value, {}))
            )
          },
          validations: {}
        ),
        
        a!paragraphField(
          label: "DEBUG",
          value: local!selectedOptions,
          disabled: true()
        )
      }
    )

Children
No Data