cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
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
Highlighted
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

Highlighted

@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
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 (9,520)