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:
Name | Phone Number | Title |
Name1 | 12345 | Title1 |
Name2 | 1234512345 | Title2 |
Name3 | 123451234512345 | Title3 |
When I perform my ForAll() and Patch() functions, this is the result in SharePoint:
Name | Phone Number | Title |
Name1 | 12345 | Title1 |
Name1 | 12345 | Title1 |
Name1 | 12345 | Title1 |
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:
As you can see, the Collection references it correctly but Patching it will look like this:
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. 😞
Solved! Go to Solution.
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
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
@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!
User | Count |
---|---|
180 | |
114 | |
88 | |
44 | |
42 |
User | Count |
---|---|
226 | |
113 | |
112 | |
69 | |
67 |