Showing results for 
Search instead for 
Did you mean: 
Frequent Visitor

BUG REPORT - Duplicate patch functions firing in Datatable OnSelect

I see some reference to OnSelect functions firing twice, I am trying to patch data to a SharePoint source OnSelect, here is my code: 

If(DataTable7.Selected.status = "Needed", Set(NextAvailableID, First(Sort(Repair, ID_Repair, SortOrder.Descending)).ID+80);
Patch(Repair, {SerialNumber: DataTable1.Selected.SerialNumber, ID_Repair: NextAvailableID, RepairComments: "test"});Patch(ProcessedECO, {RepairID: NextAvailableID, ProECO_DateComplete: Today(), ProECO_Initials: User().FullName, ECONumber: DataTable7.Selected.ECONumber});  Navigate(PatchSingleECO, Fade), Navigate(RepairDetails));

Both "Repair" and "ProcessedECO" are SharePoint data sources, records are being created twice when this fires. I have tried with/without the defaults() parameter as I thought that was the cause, but no luck.  Is this in fact a bug, and is there an ETA on a resolution?  The similar tickets I only see reference to it being a bug and to report it. 


Super User
Super User


What are you trying to do: add a record or update a record?  The Patch function typically has three arguments:


PATCH(datasource, record, {update})


In your Patch function I only see two arguments:  datasource and record.  Maybe this is why your code is not working?


//your code
Patch(Repair, {SerialNumber: DataTable1.Selected.SerialNumber, ID_Repair: NextAvailableID, RepairComments: "test"});

//my annotation
Patch(Repair,missing_record_argument,{SerialNumber: DataTable1.Selected.SerialNumber,ID_Repair: NextAvailableID, RepairComments: "test"});


To add record you would typically this.

Patch(Repair,Defaults(Repair),{SerialNumber: DataTable1.Selected.SerialNumber,ID_Repair: NextAvailableID, RepairComments: "test"});


To update a record would depend on how your app is built.  You'll have to let us know whether you want to Add or Update.


Please click "Accept as Solution" if my response helped to solve your issue so that others may find it more quickly. If your thought the post was helpful please give it a "Thumbs Up."

@mdevaney  thanks for the help.  I mentioned in the post I originally had the defaults() argument for both patch functions, I have put them back in and confirmed that duplicate records are still being created in both data sources. It is also incrementing the NextAvailableID so it appears the entire OnSelect is firing twice.


Thanks for trying the 1st idea Sheff.  Problem solving is often a process of elimination so I wanted to remove that possibility before we go further.


My next question is, does the screen navigate to this once the PATCH is done?

Navigate(PatchSingleECO, Fade)


Check the onVisible property of that screen.  Any code there?  Moving to a new screen triggers the execution of any code in onVisible.


Yes it navigates correctly, I tried a few different test screens to make sure it wasn't anything caused by the datatable on that destination screen. When I get back in front of a machine I will add the patch functions to a button and see if it still duplicates the records. Thanks for the assistance.


OK. Once you've tested some more come on back to the forums if you need a brainstorming partner.

@mdevaney  so I copied the code above but removed the If Statement from the datatable Onselect, and put just the patch functions on a button and they created the expected single record. Then to test, I removed the IF statement from the Datatable OnSelect thinking it may have contributed to the duplicates, however duplicate records are still being patched in both data sources even without the IF statement. I also manually set the repairID to rule out issues with that, and still 2 records are created. Something about the Datatable Onselect is making it execute twice.  It seems this has been reported before, the fact that this was posted nearly a year ago is troubling.  




Oh no, that's not good...  might as well go ahead and report it but... that sucks.

Helpful resources

Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,226)