Need checkbox to remain selected if set

I have this checkbox when checked sets the priority on the case. Currently the value is defaulted to 0. When its set the value updates from 0 to 100 and I should be able to check the value and if its 100 when the end user returns they will see the box is checked and can uncheck it to reset the case value back to 0.

Currently I have the functionality of setting/saving the value updating the case all working with a process model. Even when they return they can check the box again and it will set the value back to 0. But I cannot figure out how to keep the box checked like the screenshot when the end user returns. It’s always unchecked.

local!choices: if(local!case.priorityRank > 0, 0, 100),
local!updatePriorityRank: null,
 
a!sectionLayout(
      label: "",
      contents: {
        a!sectionLayout(
          label: "Case Priority",
          contents: {
        a!checkboxField(
          label: "",
          choiceLabels: {"Priority"},
          choiceValues: {local!choices},
         
          value: local!updatePriorityRank,
          saveInto: local!updatePriorityRank,
          choiceStyle: "STANDARD"
        )
    }
)

  Discussion posts and replies are publicly visible

Parents
  • Care to expand on that a bit ? Removing the null does nothing to resolve the issue.

  • 0
    Certified Lead Developer
    in reply to seenaomi

    You're initializing that local variable to a hardcoded value of null.  The checkbox field uses that local variable for its value and saveInto parameters.  I'm not clear what you were expecting it to do, but under this setup, it will only ever initialize to a state of unchecked.

  • I stated what I was trying to figure out how to accomplish behavior wise and that I was struggling to find a way to do it. I provided my code to show my setup for guidance. Is that not the point of this forum? 

  • 0
    Certified Lead Developer
    in reply to seenaomi

    Sorry, not meaning to sound snippy or anything, it's just often a struggle to discern the intent based on the limited amount of detail available in posts like this.

    I think I see what you're getting at now - let me take a stab at it.

  • +1
    Certified Lead Developer
    in reply to seenaomi

    So the first problem you're facing here is, the checkbox field doesn't work as straight-forwardly as what you're attempting.  This is understandable, it's not the easiest thing to understand especially when you're trying to use it as a boolean (and really it's not meant to be used that way, though it *can*).

    The checkbox field always assumes a LIST of items will be provided, and a LIST of values (down to an empty list) will be the VALUE.

    In your case, you're passing a hardcoded list of a single label (Priority) accompanied by a semi-hardcoded list of a single value (choices, so either 0 or 100).  But your saveInto is not making any accounting for what you're actually trying to accomplish - that is, switching between 0 or 100.  You'll need to do a bit more bending over backwards first.

    The second problem here is, your local variable (the aforementioned value and save target) is not making any reference to the current value of local!case upon form load.  So as I mentioned before, it will always load blank.  The way the checkbox field works, when you pass in a blank value as the value of the list of the checkboxValues list (regardless of what the valid values list contains), it'll populate the checkbox as empty.

    Stand by and I'll try to whip up a code snippet with things rearranged in such a way that they work more as you're expecting here, and you might see what I mean.

  • +1
    Certified Lead Developer
    in reply to seenaomi

    PFA the attached somewhat-reworked sample code / portable interface (bypassing "local!case" and instead establishing an initial value that you can just switch between 0 and 100 to test both presets).

    a!localVariables(
      
      /* change this value to either 0 or 100 by commenting or
          un-commenting the "0" row, then pressing "test" */
      local!testPriorityRank: {
        /*0,*/
        100
      }[1],
      
      local!choices: {100},
      
      local!checkboxCurrentValue: if(
        local!testPriorityRank = 100,
        {100},
        {}
      ),
      
      /* setting this value using local variable update chaining so you can pass it back to the process / etc to update your case priority rank value.  it doesn't have any other function in this test interface. */
      local!updatePriorityRank: a!defaultValue(
        index(local!checkboxCurrentValue, 1, null()),
        0
      ),
      
      a!sectionLayout(
        label: "Case Priority",
        contents: {
          a!checkboxField(
            label: "",
            choiceLabels: {"Priority"},
            choiceValues: {local!choices},
    
            value: local!checkboxCurrentValue,
            saveInto: {
              local!checkboxCurrentValue
            },
            choiceStyle: "STANDARD"
          ),
          
          a!richTextDisplayField(
            label: "Evaluated Priority:",
            value: a!richTextItem(
              text: local!updatePriorityRank,
              style: "EMPHASIS"
            )
          )
        }
      )
    )

  • This is fantastic! I really appreciate the help - I've been mulling through docs trying to sort out the best way to achieve this. I should have came here much sooner. Thank you!

  • +1
    Certified Lead Developer
    in reply to seenaomi

    No prob!  And just FYI, a long time ago I got tired of the manual finagling needed to make a checkbox like this handle a simple on/off switch, so I wrote a reusable custom component that I save in a generalized format and then call when needed.  I posted it a few years ago in this thread if you'd like to check it out - including explanations of how it works, etc.

Reply Children
No Data