How to set a boolean property for one (and only one) list item ... be like a radio button selection


I would like to allow a model user to flag ONE member of a list as the "base item".  If the user changes a leaf-level list item's "base item" flag to TRUE, then all other leaf-level list items that were previously marked TRUE should be marked FALSE. One and only one item must be "base item" = TRUE at any given time.


(Use case:  Calculated line items will use this information to either compute values from inputs for all "base item" = FALSE  items.  For the one "base item" = TRUE item, the calculation applies different logic that "plugs" the remainder.)

Best Answer

  • PaulRitner



    There are lots of ways to do this, but I think this is the easiest (if the parent list is a separate list):  select the TRUE leaf item at the parent level (i.e. create a module that includes the parent list, and then add a line item that is formatted to the Child/Leaf list, and select the one leaf item there... and then set the booleans accordingly at the leaf level, based on that single parent level (leaf) selection.  This is simple & has the benefit of not permitting more than one leaf item to ever be selected.  However, if the parent is in the same list as the leafs, then you can't use this.


    If the parent is in the same list as the leafs, another way to do this is as follows:

    1. Create a module based on the list with a boolean line item (so users can check the one leaf).
    2. Create an audit to validate that only one (sibling) leaf is selected at a time.  There are a couple ways to do this, but I'd consider having adding the following line items:  one that converts the boolean TRUE to a number 1, and a second that grabs the parent level aggregation of the 1's to see if the value is <> 1 (if it is <> 1 then you can use some conditional formatting to flag the error.  Also, you can use TEXTLIST to immediately display the (multiple items that are checked) if that type of error applies.  Regarding TEXTLIST, you could search the textlist for an empty string (which means there is no leaf checked) or search it for a comma (which means there are multiple items checked).


    If you really want to get snazzy, and if there aren't too many users in the system at a time, and perhaps if the list containing your leaf items isn't too big, then you could create a bulk process where user's would be able to (just throwing mud at the wall here): select leaf you want to be true... and then click a button that loads a TRUE to that leaf while loading falses to all of that leaf's siblings.  There are a couple of nuances here that would need to be thought through and unit tested.  For example, what list will you use in the selection module?... could be a user list.  You probably still want to audit the process as a whole... so you might include some elements of the 2nd option anyway.