cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Prajnya
Helper I
Helper I

How to restrict multiple time adding a single user in PowerApps

Hi Experts,

 

I am building a PowerApps application on Project Management. For Project Members I have used multiple people Picker field. 

Prajnya_0-1614875256161.png

For Memebers: I have used Combo Box. 

Items: If(
IsBlank(ProjectMembers.SearchText),
Office365Users.SearchUser({searchTerm: Text("null")}),
Office365Users.SearchUser(
{
searchTerm: ProjectMembers.SearchText,
top: 1
}
)
)

On change: If(
IsBlank(ProjectMembers.Selected.DisplayName),
Reset(ProjectMembers),
Collect(
colMembersToAdd,

{
Claims: Concatenate(
"i:0#.f|membership|",
ProjectMembers.Selected.Mail
),
DisplayName: ProjectMembers.Selected.DisplayName,
Email: ProjectMembers.Selected.Mail,
UPN:ProjectMembers.Selected.UserPrincipalName
}
);
Reset(ProjectMembers)
);

 

Below Box I have taken Gallery and its Item property to colMembersToAdd

The above is working fine. 

But my problem is User can add one memeber multiple times. How can I restrict it.

please suggest . Thanks

7 REPLIES 7
Suchitra1996
Resolver II
Resolver II

Hi @Prajnya 

 

I made a test on my end, instead of using your logic, I used below function on "Items" property of the combobox:

Office365Users.SearchUser({searchTerm:ComboBox1.SearchText})

 

I also changed the fields property as below:

Suchitra1996_0-1614879919251.png

 

 

Instead of using a collection, I directly updated  the gallery "Items" property to:

ComboBox1.SelectedItems.DisplayName

and within the gallery I just have a label that defaults to "ThisItem.DisplayName"

 

I don't think we can select a person multiple times as long as there are no duplicate members. If you select an already selected member from combobox, it deselects that item.

 

Suchitra1996_1-1614880055266.png

 

 


--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

 

 

Prajnya
Helper I
Helper I

Hi Suchitra

Thanks for your Reply. This can be done, but the problem here is how to restrict one user adding multiple times

 

Example: If User1 is already added in gallery then User1 can not be added once more 

Please suggest. Thanks

Suchitra1996
Resolver II
Resolver II

@Prajnya 

 

Please refer the below screenshot:

 

Suchitra1996_0-1614939971544.png

I used two comboboxes, used collection this time, and applied below condition to the OnChange property of both:

If(IsBlank(ComboBox1.Selected.DisplayName),Reset(ComboBox1),IsBlank(LookUp(colMembersToAdd,DisplayName in ComboBox1.Selected.DisplayName,DisplayName)),Collect(
colMembersToAdd,

{
Claims: Concatenate(
"i:0#.f|membership|",
ComboBox1.Selected.Mail
),
DisplayName: ComboBox1.Selected.DisplayName,
Email: ComboBox1.Selected.Mail,
UPN:ComboBox1.Selected.UserPrincipalName
}
));
If(IsBlank(ComboBox1_1.Selected.DisplayName),Reset(ComboBox1_1),IsBlank(LookUp(colMembersToAdd,DisplayName in ComboBox1_1.Selected.DisplayName,DisplayName)),Collect(
colMembersToAdd,

{
Claims: Concatenate(
"i:0#.f|membership|",
ComboBox1_1.Selected.Mail
),
DisplayName: ComboBox1_1.Selected.DisplayName,
Email: ComboBox1_1.Selected.Mail,
UPN:ComboBox1_1.Selected.UserPrincipalName
}
));

 

As you can see in the screenshot above, If User1 is already in the gallery, it is not added again.

Prajnya
Helper I
Helper I

@Suchitra1996 

Hi Suchitra,

 

This one is the correct approach. 

But I tried something like this and it worked 

 

Onchnage of ProjectMembers Combo Box

If(
IsBlank(ProjectMembers.Selected.DisplayName),
Reset(ProjectMembers),
If(
CountRows(
Filter(
colMembersToAdd,
( DisplayName = ProjectMembers.Selected.DisplayName)
)
) < 1,
Collect(
colMembersToAdd,
{
Claims: Concatenate(
"i:0#.f|membership|",
ProjectMembers.Selected.Mail
),
DisplayName: ProjectMembers.Selected.DisplayName,
Email: ProjectMembers.Selected.Mail,
UPN:ProjectMembers.Selected.UserPrincipalName
}
);
Reset(ProjectMembers)
));

 

My challenge here is I have another combo box which select Project Manager. I have two options to handle this 

1. Project manager can not be a Project Member ( How to restrict this)

2. Add Project Manager in "colMemberstoadd" collection(Unique collection, no double entry of any user)

 

Please help me in this

Prajnya_0-1614960352221.png

 

Suchitra1996
Resolver II
Resolver II

@Prajnya 

 

Do you want that if anyone is added as a member in the gallery,

they should not be a part of the manager combobox, or

that they should not be added if already added as a member.? In this case, you can use the second combobox that i mentioned in my previous comment.

@Suchitra1996 

Thanks for Replying.

 

In my case, The Person name added in Project Manager combo box can not be add in Project Member Combobox or Project Manager to be add in Collection - colMembersToAdd

Prajnya
Helper I
Helper I

Prajnya_0-1615045240359.png

@Suchitra1996 Thanks for guiding me 

 

Please refer the above image. 

Using your above logic I am able to get a unique list of Project Member, but the requirement is Project Manager can not be a Member. If I am Selecting "Priyadarsini Prajnya" in Project Manager then I cant Select it in Project Member.

 

Please guide me in this. Many Thanks in advance

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Power Apps Community Call Jan. 2022 768x460.png

Power Apps Community Call

Please join us on Wednesday, January 19th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (995)