cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Adding multiple records with ForAll based on allow multiple selection people picker but want to make sure no duplicates added

I have an app for adding users to an event and it works well. For the On Select of the Submit button I have the code below to check that if Is Blank Lookup the Registration list Event Title=Event List Event Title and the Registration List User Display Name=Data Card Value Selected Display name, then Submit the form & Update Context of form to false, else Notify the user they are already registered, reset the form and Update Context of form to false. This makes sure that for the Event chosen that the user hasn't already been signed up to attend the event.

If(IsBlank(LookUp('Event Registration', And(Event_x0020_Title=Title9.Text, Registered_x0020_User.DisplayName=DataCardValue15.Selected.DisplayName))),
SubmitForm(MultiUserForm) & UpdateContext({MultiUserFormVar:false}),Notify("You are already registered for this event.",NotificationType.Error) & UpdateContext({MultiUserFormVar:false}))

Screenshot 2020-11-20 113134_LI.jpg

I have changed the people picker to allow multiple selections and make each selection a separate record in the SP list using ForAll and Patch functions code below.Screenshot 2020-11-20 112118.png

 
ForAll(DataCardValue17.SelectedItems,Patch('Event Registration',{'Event Title': Title9.Text,'Event Session': DataTable1.Selected.Session.Value,'Registered User': {
'@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",Claims: Claims,Department: Department,DisplayName: DisplayName,Email: Email,JobTitle: JobTitle,
Picture: Picture}}))

Screenshot 2020-11-20 113828.png

 

What I would like to be able to do is compare the People Picker multiple Selected Items to the SP list Registered Users and make sure a duplicate doesn't exist like I did with registering a single user, but I am inexperienced with PowerApps functions and can't seem to get the code to do both using On Select for the Submit button. Hopefully I have explained my issue well enough that someone can provide suggestions to remedy my problem.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Microsoft
Microsoft

Hi @jready ,

 

Could you please share more details about your scenario? What if there are duplicate record for the same user with same event title, submit all records without duplicate ones or not submit at all but giving error prompts?

 

If you would like to submit records except those duplicate ones, you could simply add the ForAll function in the original formula:

Forall(DataCardValue17.SelectedItems,If(IsBlank(LookUp('Event Registration', And(Event_x0020_Title=Title9.Text, Registered_x0020_User.DisplayName=ThisRecord.DisplayName))),
SubmitForm(MultiUserForm) & UpdateContext({MultiUserFormVar:false}),Notify("You are already registered for this event.",NotificationType.Error) & UpdateContext({MultiUserFormVar:false})))

Not exact correct since the update context and notification.

 

If you would like to prevent submitting at all when duplicate user exists, you could do a validation before submitting:

Forall(DataCardValue17.SelectedItems,Collect(colVal,{Value:If(!IsBlank(LookUp('Event Registration', And(Event_x0020_Title=Title9.Text, Registered_x0020_User.DisplayName=DisplayName))),1,2)}));
ClearCollect(colTotal,{total:1});
ForAll(colVal,Patch(colTotal,First(colTotal),{total:First(colTotal).total*Value}));
If(colTotal.total=1,SubmitForm(MultiUserForm) & UpdateContext({MultiUserFormVar:false}),Notify("You are already registered for this event.",NotificationType.Error) & UpdateContext({MultiUserFormVar:false})))

The first ForAll creates a collection colVal with Value column stores validation results, if selected user duplicates return 1 otherwise return 2. The second ForAll multiply all the values and stores the result in collection colTotal. In the end, if no duplicate user the result should be 1 then submit all, if any duplicate user exists the result would be more than 1 then would not submit and the error message prompts.

 

Hope this helps.

 

Best regards,

Community Support Team _ Jeffer Ni
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

2 REPLIES 2
Highlighted
Microsoft
Microsoft

Hi @jready ,

 

Could you please share more details about your scenario? What if there are duplicate record for the same user with same event title, submit all records without duplicate ones or not submit at all but giving error prompts?

 

If you would like to submit records except those duplicate ones, you could simply add the ForAll function in the original formula:

Forall(DataCardValue17.SelectedItems,If(IsBlank(LookUp('Event Registration', And(Event_x0020_Title=Title9.Text, Registered_x0020_User.DisplayName=ThisRecord.DisplayName))),
SubmitForm(MultiUserForm) & UpdateContext({MultiUserFormVar:false}),Notify("You are already registered for this event.",NotificationType.Error) & UpdateContext({MultiUserFormVar:false})))

Not exact correct since the update context and notification.

 

If you would like to prevent submitting at all when duplicate user exists, you could do a validation before submitting:

Forall(DataCardValue17.SelectedItems,Collect(colVal,{Value:If(!IsBlank(LookUp('Event Registration', And(Event_x0020_Title=Title9.Text, Registered_x0020_User.DisplayName=DisplayName))),1,2)}));
ClearCollect(colTotal,{total:1});
ForAll(colVal,Patch(colTotal,First(colTotal),{total:First(colTotal).total*Value}));
If(colTotal.total=1,SubmitForm(MultiUserForm) & UpdateContext({MultiUserFormVar:false}),Notify("You are already registered for this event.",NotificationType.Error) & UpdateContext({MultiUserFormVar:false})))

The first ForAll creates a collection colVal with Value column stores validation results, if selected user duplicates return 1 otherwise return 2. The second ForAll multiply all the values and stores the result in collection colTotal. In the end, if no duplicate user the result should be 1 then submit all, if any duplicate user exists the result would be more than 1 then would not submit and the error message prompts.

 

Hope this helps.

 

Best regards,

Community Support Team _ Jeffer Ni
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

Highlighted
Frequent Visitor

Hey @v-jefferni  - It looks like that put me on the right path. Below is the code I used and it seems to be working. Thank you!

 

ForAll(DataCardValue17.SelectedItems,If(IsBlank(LookUp('Event Registration',And(Event_x0020_Title=Title9.Text,Registered_x0020_User.DisplayName=DataCardValue17.Selected.DisplayName))),SubmitForm(MultiUserForm),Notify("User is already registered for this event.",NotificationType.Error)))

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (12,931)