Handling Dropdown Field Error

Hi Expert,

I want to design the code in such a way that if I'm using a dropdown field and somehow one of the value gets deleted from the backend or the constant holding the values get updated.

How can we handle such situation so that no errors should popup to end users.

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    This is handleable but takes some extra work and requires tweaking depending on exactly how your system will be configured.

    For dropdown values stored in the database, a common Best Practice is to never delete the value, but instead set it to inactive per an "active" or "deleted" column (just one or the other per your preference, not both).

    In this case if we assume a user will be getting a task where a dropdown is pre-populated with a previously selected value corresponding to a DB entry that may have been set to inactive in the mean time, you just need to handle your local variables carefully and you can cover this scenario.

    First you would query the (currently active) reference values into a local variable as normal.  This could be local!dropdownValues.  In a subsequent local variable you could check whether the pre-loaded reference variable ID is contained in the queried local!dropdownValues, and if not, do a query into the reference table based on the pre-loaded ID (even if it's deactivated).  This could be local!deactivatedValue.

    Then in your dropdown field you can set the values and labels parameters to make use of the deactivatedValue when it's present, and have the field throw a validation error ensuring that the user is warned that they need to select a currently-valid option before continuing.