web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patch functions create...
Power Apps
Unanswered

Patch functions created duplicate record

(0) ShareShare
ReportReport
Posted on by 70

I have this function in my canvas app and on button clicked I am patching my collection in Dataverse table Order and Order details. My col name is Product for check. I have loading spinner when button clicked that disables screen, I have IsPatchingInProgress that disables the button. I also empty collection after Patch. The problem is that sometimes this functions creates 2 duplicate order and sometimes even 4 duplicate orders. Do you know how is this possible. 

Set(
LoadingSpinnerVisibilty,
true
);
Set(IsPatchInProgress, true);
Set(
CurrentOrder,
Patch(
'Order',
Defaults('Order'),
{
Company: CurrentUser.'Business Unit',
Customer: SelectedCustomer,
'Total value': Sum(ProductsForCheck,Sum(totalvalue)),
Delivery:drpDelivery.Selected.Value,
'Customer Text':SelectedCustomer.'Account Name',
'Customer Reference':varcustref

}
)
);
ForAll(
ProductsForCheck,
Patch(
'Order Details',
{
'Product Name': productname,
'Product Number': productNo,
Quantity: Value(quantity)
}
)
);

Reset(ComboBox1);
Set(
resetCustomer,
true
);
Set(
resetSearch,
true
);
Set(
LoadingSpinnerVisibilty,
false
);
Notify("Order successfully submitted",NotificationType.Success);
Set(IsPatchInProgress, false);
If(
CountRows(Filter(ProductsForCheck, Value(additionaldiscount) > 0)) > 0,
Set(showDiscountNotificationPopup,true),
Clear(ProductsForCheck); Reset(txtSearchCustomer); Set(SelectedCustomer,Blank())
)

 

 

Categories:
  • Michael E. Gernaey Profile Picture
    53,975 Super User 2026 Season 2 on at

    @MarinaPA 

     

    Hi. Firstly, you shouldn't use a variable to try to disable the button. There is already a Property that sets it to auto disabled, when you press it (and until it completes).

     

    I actually do not see anything wrong with your code that would cause it, that being said, you are showing us a very small part, with assumption the issue is in the button.

     

    You also mention you are patching a collection into Dataverse, but none of the code for Order (specifically order, as you said Order is being duplicated++ not the Order Details), above is using a collection. Are you showing the correct code?

     

    Do you mean Order Details, or Orders are being duplicated++?? If its order details, then its an easy check on validating the Collection, prior to hitting Submit. If its Order, then there isnt enough data points here to tell you.

     


    If I have helped you, I would really appreciate if you please Mark my answer as Resolved/Answered, and give it a thumbs up, so it can help others

    Cheers

    Thank You
    Michael Gernaey MCT | MCSE | MCP | Self-Contractor| Ex-Microsoft
    https://gernaeysoftware.com
    LinkedIn: https://www.linkedin.com/in/michaelgernaey

     

  • RobertLHUHome Profile Picture
    9 on at

    I am dealing with the same dataverse bug.  Patch() is creating duplicate primary key values 😯 How is this possible?  I've used this structure successfully with SQL Server, but doesn't work with DV.  By including the GUID field(highlighted), the Patch() will edit records instead of adding new records.  (Also great article from David Wyatt attached). Bulk edit with Patch() 

    RobertLHUHome_1-1703689906981.png

     

     

    RobertLHUHome_0-1703689744195.png

     

  • RobertLHUHome Profile Picture
    9 on at

    @FLMike any ideas on this?

  • Michael E. Gernaey Profile Picture
    53,975 Super User 2026 Season 2 on at

    Hi @RobertLHUHome 

     

    A couple things

    I am not sure you are dealing with what the previous user is, in their case they are looping and never answered my questions, so it most likely a bug in their code, since it created 1- M duplicates, that usually means the loop and items in it got triggered more than 1 time.

     

    1. You say the GUID field, but that isn't a guid, its simply looks like a counter to me and there is no way to guarantee based on multiple things, that a counter will be unique, I wish there was, but there isn't.

     

    2. Yes, it is supposed to EDIT records if it exists already, but in your case again thats not a GUID. I am assuming you made it a secondary key? (You cannot make it the primary, because the GUID of a dataverse table is always the primary). You can only add secondary keys.

     

    Here is what I would suggest, and I bet you find that things are trigging multiple times and based on how you have it setup, the keys dont "have" to be unique, if that was a unique field, I've no idea how you would ever put in a duplicate, even by accident.

     

    Please do the following.

    If you can repro the steps, and you have a clean Monitor output, you will be able to see if it in fact is triggering multiple times.

     

    Please also provide screenshots of the configuration where that field is setup as a secondary unique key.

     

    Step 1. Close your App (stop it running)

    Step 2. Click the Stethoscope in the Top Right

    Step 3. On the bottom click Open Monitor

    Step 4. Once Monitor is running go back and run your app

    Step 5. Cause your issue to happen

    Step 6. Close the app

    Step 7. Go to the Monitor and Filter (top right) based on Error, or key word. Go to the line or lines that match this

    Step 8. Look at the Response Tab and you will have to expand the Body > and the Header >. Then look at the body to see more details on the error
    Do this for each line you find


    Step 9. On each line, also check the Code being executed on Tab 2

     

    Thanks


    If I have helped you, I would really appreciate if you please Mark my answer as Resolved/Answered, and give it a thumbs up, so it can help others

    Cheers

    Thank You
    Michael Gernaey MCT | MCSE | MCP | Self-Contractor| Ex-Microsoft
    https://gernaeysoftware.com
    LinkedIn: https://www.linkedin.com/in/michaelgernaey

  • RobertLHUHome Profile Picture
    9 on at

    I've renamed the column, but I understood this "primary" column is a GUID.

    RobertLHUHome_0-1704310594317.png

    Am I missing the mark right out of the gate? 
    Perhaps this then is my GUID.  I looked at the end and thought it was the same for every row.  I didn't expect the beginning to the be unique part.  🧱🤕. 

    RobertLHUHome_1-1704312398606.png

    INDEED, after using the new (correct) GUID column, the Patch() correctly edited records without duplicates.  

  • Michael E. Gernaey Profile Picture
    53,975 Super User 2026 Season 2 on at

    @RobertLHUHome 

     

    yes that is a GUID, and to verify, you should always go look at the table definition and it will literally be listed as the Unique Column

     

    Glad I could help. If you don't mind marking my response as the answer, as it was. I'd appreciate it.


    If I have helped you, I would really appreciate if you please Mark my answer as Resolved/Answered, and give it a thumbs up, so it can help others

    Cheers

    Thank You
    Michael Gernaey MCT | MCSE | MCP | Self-Contractor| Ex-Microsoft
    https://gernaeysoftware.com
    LinkedIn: https://www.linkedin.com/in/michaelgernaey

  • MarinaPA Profile Picture
    70 on at

    @FLMike hi, I am using a component button and don't have auto disable property there. I am patching some general information in a table Order and items from my collection Orders for check in a table called Order Details. On one click of a button sometimes not all the time, that has this formula two record are created in Dataverse, 2X Order with Order Details. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 236 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 188 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 130

Last 30 days Overall leaderboard