How to deal with changing dropdown values

Certified Senior Developer

I have a dropdown component and I want certain values to be available for choice based on the security groups of the user. For example someone who is only in group A might be able to choose 1, 2 or 3 from a dropdown, someone in group B might be able to choose 4, 5 and 6 from the dropdown and someone who is in both groups would be able to choose all 6 options. Changing the dropdown labels/values based on group is not a big deal to do, however, since the dropdown only allows values to exist that are within the currently available list of labels/values, if group A chooses 1 and someone in group B looks at the form, the 1 will be invalid and break the interface. What would be a good way to get around this issue? 

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    If it is a security concern to show the selected values to different group of users add a visibility condition to that dropdown filed using show when. Only show this component or value if they have visibility permission.

  • 0
    Certified Senior Developer
    in reply to Naresh

    It's not that we want the dropdown gone entirely based on the group. We want the choices available within the dropdown to change based on the user. We still need the same dropdown and that dropdown has to write to the same field regardless of the group so we can't have 2 different dropdowns 

  • 0
    Certified Lead Developer
    in reply to Marco

    You didn't understand what I mentioned I am saying based on your needs you can either hide the drop down (Note: this is considering they are seeing read only version form) or don't show the value for that field.

    Also, Note the best practice to show dropdown values in read only form is using text field. see the sample example

    a!localVariables(
      local!loggedUserPermissionValues: {1,2},
      local!selectedValue: 3,
      local!readOnly: true,
      {
        a!textField(
          label: "Any Label",
          showWhen: local!readOnly,
          value: if(
            contains(local!loggedUserPermissionValues, local!selectedValue),
            local!selectedValue,
            /*You can provide any default value here like N/A, -, dont have permisson to vise this value*/
            "N/A"
          ),
          readOnly: local!readOnly
        ),
        a!dropdownField(
          label: "Any Label",
          showWhen: not(local!readOnly),
          choiceLabels: {1,2,3},
          choiceValues: {1,2,3},
          value: local!selectedValue,
          saveInto: {
            local!selectedValue
          }
        )
      }
    )

  • 0
    Certified Lead Developer

    Hi if your issue is just for the dropdown error you can use contains in the values

     

    a!localVariables(
      local!selectedValue: 7,
      local!choiceLabels: { 1, 2, 3, 4, 5 },
      {
        a!dropdownField(
          label: "Any Label",
          placeholder: "--Select a value--",
          choiceLabels: local!choiceLabels,
          choiceValues: local!choiceLabels,
          value: if(
            contains(local!choiceLabels, local!selectedValue),
            local!selectedValue,
            null
          ),
          saveInto: { local!selectedValue }
        )
      }
    )