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

ForAll and Patch() function duplicates collection and SharePoint data

Hey there,

 

I have an app that supposedly patches a collection to a SharePoint list. ForAll() and Patch() function seems to work and is patching the data, but the data being patched only repeats it for the total number of records I've created. For example, I have this collection. Let's say these are stored in a collection named colNewContacts:

 

NamePhone NumberTitle
Name112345Title1
Name21234512345Title2
Name3123451234512345Title3

 

When I perform my ForAll() and Patch() functions, this is the result in SharePoint:

 

NamePhone NumberTitle
Name112345Title1
Name112345Title1
Name112345Title1

 

Basically it just repeats the first item in the collection.

 

Scenario:

 

I have a button that pops up a gallery that initializes the collection:

 

//Displays the modal/gallery
Set(varNewCloseContact, true);
//Creates a new Collection so I can enter new records in the gallery
ClearCollect(colNewContacts,{ContactName:"", ContactNumber : "", ContactTitle: "", MasterID :0})

 

 

And for each gallery record, I have an add button to create a new collection record, so whenever I click that (OnSelect), this is the code:

 

Patch(colNewContacts,ThisItem,{ContactName:ContactNameText_2.Text,ContactNumber:ContactNumberText_2.Text,ContactTitle:ContactTitleText_2.Text,MasterID:varGalSelectedContact.ID});
Collect(colNewContacts,{ContactName:"",ContactNumber:"",ContactTitle:""})

 

I think I have no issues with this since it's saving my record as checked in a Data Table, and inserting another new one so that I can add new records in the gallery.

 

But on my Submit button, this is the code:

 

ForAll(colNewContacts,If(!IsBlank(ContactName),Patch('Close Contacts',Defaults('Close Contacts'),{ContactName : ContactNameText_2.Text, ContactNumber : ContactNumberText_2.Text,ContactTitle: ContactTitleText_2.Text,MasterID : varGalSelectedContact.ID})));

//Clear the Collection of what was patched, then Clear and create a new collection that shows all records based on MasterID where the gallery is selected
Clear(colNewContacts);ClearCollect(colDisplayGalContacts, Filter('Contact Tracing - Close Contacts',MasterID = galContactTracing.Selected.ID))

 

 

To recap, my issue is that it's patching the SharePoint list with the same first record over and over again based on the number of records I entered. Also to see the collection data table, here's a sample of it:

 

patchsamerecords.jpg

 As you can see, the Collection references it correctly but Patching it will look like this:

 

patchsamerecords2.jpg

 

I would appreciate it if anyone can shed light on this issue. I've been using the same strategy for a lot of my clients now and this is the only time I've experienced this. 😞

1 ACCEPTED SOLUTION

Accepted Solutions
Resolver IV
Resolver IV

Hi!

 

The problem is that in your ForAll loop, you are refencing to the input controls in the gallery rather than column names from your collection. Try this formula for the Submit button instead:

ForAll(colNewContacts,If(!IsBlank(ContactName),Patch('Close Contacts',Defaults('Close Contacts'),{ContactName : ContactName, ContactNumber : ContactNumber,ContactTitle: ContactTitle,MasterID : varGalSelectedContact.ID})));

 

BR

Pontus

View solution in original post

2 REPLIES 2
Resolver IV
Resolver IV

Hi!

 

The problem is that in your ForAll loop, you are refencing to the input controls in the gallery rather than column names from your collection. Try this formula for the Submit button instead:

ForAll(colNewContacts,If(!IsBlank(ContactName),Patch('Close Contacts',Defaults('Close Contacts'),{ContactName : ContactName, ContactNumber : ContactNumber,ContactTitle: ContactTitle,MasterID : varGalSelectedContact.ID})));

 

BR

Pontus

View solution in original post

@pontusofsweden d'oh, that's the answer and how bad of me to have overlooked it! I was scratching my head last night what it was. Thank you!

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (49,688)