Skip to main content
February 22, 2022
Solved

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

  • February 22, 2022
  • 17 replies
  • 1 view

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,

    Best answer by mikes0011

    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()
        )
      }
    )

    17 replies

    gopalk2865
    Participating Frequently
    February 22, 2022

    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.

    February 22, 2022

    Thanks.

    I get what you wrote as I pasted:

    however I am getting this error.

    andrewh0007
    February 22, 2022

    Can you post your code?

    stewart.burchell
    February 22, 2022

    Like any "multiple" you should store the values in an array. How they should be subsequently stored entirely depends on what downstream processing you want to conduct on these values. 

    andrewh0007
    February 22, 2022

    I wouldn't say this has just one answer. You can save it in many different ways depending on your exact use case but what I would say is I've seen many times that people box themselves into needing to save multiple values into the one database field which would then require the use of joinarray() to condense the values into one string and split() to turn it into an array again (Basically what's in here).

    I'd say this isn't ideal but obviously depends on your data design on how practical it is to create a many to one table. You'd also have to consider any reporting or views you'd need from this data in the database (if any) as although it's possible it can be problematic to split multiple values from one field.

    I'm interested in others views but the "best" way would probably be to have the options driving the checkbox selections in a table in the database and then have a many to many relationship set up to join your record to the reference table.

    For question 2, there's always disabled but if you play around with a!richTextDisplayField() you could create a cleaner version.

    February 22, 2022

    Thanks for the responses! I guess I am looking for a simple practical example.

    In essence, in order to save a textbox value.

    a!textField(
      label: "Purpose",
      labelPosition: "ABOVE",
      value: ri!record.purpose,
      saveInto: ri!record.purpose,
      characterLimit: 255,
      required: false
    )

    you need a text CDT 

    and varchar DB field

    What do I need in order to save a value that is a array in a db table? [emoticon:c4563cd7d5574777a71c318021cbbcc8]

    andrewh0007
    February 22, 2022

    You need a whole new table! [emoticon:c4563cd7d5574777a71c318021cbbcc8]