We have a problem with OnSelect of a gallery. This app was built a long time ago and I have to work with it.
Basically we have two galleries, one is to display data, and another is on another screen with the ability to update/delete/add the data.
These two galleries are using two different collections for the data.
In the second screen gallery to update the data, there is a patch() function in OnSelect. Basically if there are change to the entries in this gallery, patch works with its collection to update or add new entries.
What seems to be happening is created a function in the first gallery to duplicate data. I add the data to its collection and it seems fine. However, when I click to move to the second gallery, that is for update/delete/add, its Patch function inside OnSelect seems to execute and adds a bunch or repetitions of the duplicate line I added in the first gallery.
so if this is confusing. Even I'm confused.
Basically the second screen for update/delete/add has Clear and ClearCollect to recollect for the gallery and the data is fine, but when this second screen and gallery loads the Patch in OnSelect seems to execute and adds a bunch of repetitions in its collection? Like if I added one entry, there is that entry, and another 4 more repetitions of that entry. Which if we submit the form then these repetition entries and entered the sharepoint library. that sucks.
I even put a test collection in the OnSelect of gallery like ClearCollect(whatisgoingon, ThisItem) and I can see that on load of this screen and gallery whatever is in OnSelect executes. Why? I didn't select any entries!?
I do not understand why it executes AND then adds multiple repetition of the entry or entries I added. I understand why they put the patch there in OnSelect, because they want to patch "ThisItem", but why does it run on load?
Here is an idea of the code
second screen on visible has:
Clear()
ClearCollect(secondcollecction,Filter(table, ID = whatever))
and in the second gallery's OnSelect this is the patch:
Patch(
secondcollection,
ThisItem,
{
Title: txtSAFProject.Text & "_" & cboSAFType.Selected.Value & "_" & cboSAFFY.Selected.Value,//txtSAFTitle.Text,
SAFType: cboSAFType.Selected,
FY: cboSAFFY.Selected,
ProjectPhase: cboSAFProjectPhase.Selected,
ProjectID: Value(txtSAFProjectID.Text),
Project: txtSAFProject.Text,
SAFAmount: Value(txtSAFAmount.Text)
}
);