Preventing a User Picker Field from allowing you to select the same user twice

I am using a User Picker Field in an interface and filtering the users by group. However the field allows me to select the same user multiple times.

Is there a way to remove a user from the dropdown field if they have already been selected?

 

I have found a way to prevent selecting a user multiple times, but it would be better if the user just didn't appear in the dropdown because they have already been selected.

  Discussion posts and replies are publicly visible

  • The only way I know of to prevent the same user from being selected twice in the native user picker is to use validations (which, judging from the last sentence in your post you're already doing). Preventing them from being displayed in the suggestions once they've been chosen isn't possible as far as I know. You can get around it by building instead a custom picker that accomplishes the same purpose, but with a suggest function that will filter already selected results. It will also allow you other additional controls over the behavior of the picker. The drawback there, however, is it will not look as nice as the default user picker since it won't have the same formatting or the user pictures.
  • There may be a more ideal way to accomplish this, but in the past I've used the union() function to accomplish this:

    union(local!selectedUsers,local!selectedUsers)

  • I believe you that you may be able to use the difference function, where you pass in two arrays and it returns only the unique values from each array.
    difference(local!selectedUsers, local!userList) should only return the list of users that are not already selected.
  • simple use union function in value, it will never re-select same user, here is the sample code:
    a!pickerFieldUsers(
    label:"Select Users:",
    value:union(local!abc,local!abc),
    saveInto:local!abc

    )
  • Hello Andrewknott,
    You can use rule!APN_distinct() this rule if you are using Appian 17.3V . Here Code snippet
    rule!APN_distinct({"q","d","d"}), you have to use this at value in Picker filed component. It might helpful for your requirement.
    Let me know if it works.
  • 0
    Certified Lead Developer
    in reply to lokeshk

    Using union() like this in the Value would actually only cause the picker to LOOK like you haven't selected the same person twice, while in fact the array of users (local!abc) *would* contain the same user twice.

    What you would need to do is use union() in the saveInto in such a way that if the same user is picked again, they aren't even added to the saved variable.  Such as:

    saveInto: {
    a!save( local!abc, union(save!value, save!value) )
    }

     

    Further, I would encourage you to not manually call union() for this purpose, but instead to have an expression rule defined which takes an array and removes duplicates (examples being, one I've written and used called rule!GLBL_removeArrayDuplicates(), or which  mentioned above, rule!APN_distinct(), which I presume does the same thing).

    That would end up being:

    saveInto: {
    a!save( local!abc, rule!GLBL_removeArrayDuplicates(save!value) )
    }

    And, my definition for GLBL_removeArrayDuplicates is simply:

    union(
      ri!array,
      ri!array
    )