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

Parents
  • 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

    )
  • 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
    )
Reply
  • 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
    )
Children
No Data