I am very new to PowerApps so hopefully my question is clear. I have a collection that I created called colGridData which patches new records that I create in colGridData to an online Sharepoint list. In general, this works great when the records already exist on the Sharepoint list (i.e., editing the records seems to work fine). However, when I attempt to add a record to the collection or delete a record from a collection, duplicate records get created. The unusual thing is that they don't always get created, but seemingly more at random. For example, if some cases I can add a record just fine and then in other instances I add or delete a record and multiple existing records get duplicated in the collection. Ultimately, since the records never get loaded to the Sharepoint the duplicate records disappear as I add new records to the collection or otherwise toggle within my application. One guess is that the colGridData may be updating/refreshing too quickly before the changes "take". I have set my text fields to delay update = true.
Here is the code I use when adding a record to the collection:
Set(varNumber,varNumber+1);
Collect(
colGridData,
Patch(varNewRecord,{ID:varNumber}
)
)
And then after the record is added and the fields are updated, I exit the colGridData with the following:
If(
varGridEdit,
Patch(
Nominations,
UpdateIf(colGridData,Created = Blank(),{ID:Blank()}
)
)
);
Remove(Nominations,colDelete);
Clear(colDelete);
Select(btnLoadData);
Set(varGridEdit,!varGridEdit);
Finally, here is the code in btnLoadData:
ClearCollect(
colGridData,
Filter(
Nominations,
StartsWith(Title,txtEmployeeID.Text)
&& StartsWith('Preferred Name',txtName.Text)
&& StartsWith(Status.Value,txtStatus.Text)
)
);
When an erroneous record gets added, it seems that the ID is blank and the "Created" value is also blank. Does anyone know a way to stop the erroneous records from being added? Do I need to add some code to "stop" the creation of additional blank IDs? Any guidance you can provide will be much appreciated as I learn to work within PowerApps. Thank you!