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

 

7 REPLIES 7
Highlighted
Super User III
Super User III

@Sheff 

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."

Highlighted

@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.

Highlighted

@Sheff 

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.

 

Highlighted

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.
Highlighted

@Sheff 

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

Highlighted

@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.  

 

 

Highlighted

@Sheff 

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

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 (16,079)