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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Apps
Answered

Patch conflicts

(1) ShareShare
ReportReport
Posted on by 169
Hello. I have a gallery to choose a customer. So CustID = 1, 2, etc. depending on what customer is chosen. I also have a Customer Note field that patches a Sharepoint List when it is updated (using Patch since some fields need formatting, etc.)
 
The problem is that if the user is on Cust #1, edits the Note, and then (too) quickly chooses Cust #2, the Patch is slow so that Cust #2 is updated instead of Cust #1. Is there a way to stop the user from interacting with the App until the Patch is done?
Categories:
I have the same question (0)
  • Kalathiya Profile Picture
    954 on at
    Hello @CedarTree72
     
    #1. Just to clarify, are you patching directly from a gallery itself or from a popup/modal? How the Patch is triggered.
    #2.Also, could you share the code or formula you’re using for the Patch? Seeing it will help us suggest the best way to prevent updates from going to the wrong record.
  • Suggested answer
    WarrenBelz Profile Picture
    153,684 Most Valuable Professional on at
    Assuming you are patching from an icon or a button in a gallery, change the icon/button Visible to
    ThisItem.IsSelected
    
    That way two actions are required to save - first select the record and then save it.
     
    Please ✅ Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like ♥
    Visit my blog
    Practical Power Apps    LinkedIn  
  • CedarTree72 Profile Picture
    169 on at
    Hello. The gallery on the left opens up a record in the middle of the screen (so not modal, etc.)
    When selecting a gallery item, I set a variable that points to the right customer and loads their data.
    When pathing the note, here's my code:
    Patch(
        usystblCustomers,
        ThisItem,
        {CustNote: txtCustNote.HtmlText},
    )
    I run this patch when the CustNote is updated ("on change"). If I wait 5 seconds before choosing the next customer, it works. Otherwise, no.
  • Verified answer
    WarrenBelz Profile Picture
    153,684 Most Valuable Professional on at
    @Kalathiya may also have some ideas on this, but assuming that txtCustNote is a Rich Text Control in the pop-up, you need to stop the user selecting another record while the Patch is happening, so do this
    UpdateContext({varWait: true});
    Patch(
       usystblCustomers,
       ThisItem,
       {CustNote: Self.HtmlText},
    );
    UpdateContext({varWait: false});
    Then the DisplayMode of the Gallery
    If(
       varWait,
       DisplayMode.Disabled,
       DisplayMode.Edit
    )
     
    Please ✅ Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like ♥
    Visit my blog
    Practical Power Apps    LinkedIn  
  • Verified answer
    Kalathiya Profile Picture
    954 on at
    Hello @CedarTree72
     
    The issue here is that the Patch is being executed from the CustNote OnChange, which only fires when the control loses focus (for example, when the user clicks outside the text input). If the user quickly selects another customer, the gallery selection can change before the Patch completes, causing the update to apply to the wrong record.
     
    @WarrenBelz, your approach is absolutely correct only but I implemented the same solution, with a small tweak: I store the selected CustID in a variable and Patch using variable details instead of ThisItem, which prevents the Patch from updating the next selected record if the user clicks too quickly.
     
    You can set the variable in the Gallery OnSelect or in the icon/button inside the gallery:
    Set(g_SelectedCustomerDetails, Blank());
    Set(g_SelectedCustomerDetails, ThisItem);
    On the right side – Customer Details section add Submit / Save button and OnSelect property:
     
    UpdateContext({varWait: true});
    Patch(
        usystblCustomers,
        g_SelectedCustomerDetails,
        { CustNote: txtCustNote.HtmlText }
    );
    UpdateContext({varWait: false});
     
    Gallery DisplayMode: 
    If(varWait, DisplayMode.Disabled, DisplayMode.Edit)
    
    --------------------------------------------------------------------------------------------
    If this response resolves your issue, please mark it as the Verified Answer so it can help other community members as well.
  • WarrenBelz Profile Picture
    153,684 Most Valuable Professional on at
    A quick follow-up to see if you received the answer you were looking for. Happy to assist further if not.
     
    Please ✅ Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like â™¥
    Visit my blog
    Practical Power Apps    LinkedIn   
  • CedarTree72 Profile Picture
    169 on at
    Thank you both. Just got tied up with other items. Right now, I patch each item (say Notes, address, etc.) when it is updated. In the suggested approach, would I patch ALL items when one presses the Save button?
  • CedarTree72 Profile Picture
    169 on at
    Also, can I change the color of the Save button when the rich text field is changed, until it is pressed?
     
    The patch for the one item I'm testing now works - THANKS. I removed the Patch coding from the "onchange" aspect of the Customer Note field. However, I can still pick another customer without saving and lose my changes (hence the Save button color question or any other suggestions you might have)! Thanks!

    Basically, I want to warn the user that the save button needs to be pushed.
     
  • Verified answer
    WarrenBelz Profile Picture
    153,684 Most Valuable Professional on at
    Short answer - yes - save everything you want to patch when you press the Save button. 
     
    If you want the button to change colour when something is changed in the Rich Text Editor (use your colours - the second one represents a change)
    If(
       txtCustNote.HtmlText = ThisItem.CustNote, 
       Color.Blue, 
       Color.Green
    )
     
    However if you really want to "lock" a user to a record and you are now using a separate button, please have a read of this blog of mine, a process I use in all my prod apps. It effectively commits the user to the selected record where their only two options once selected are to either save or cancel the edit before selecting another record.
     
    Please ✅ Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like ♥
    Visit my blog Practical Power Apps    LinkedIn  
  • VASANTH KUMAR BALMADI Profile Picture
    176 on at

    Yes — this is a classic timing issue in Power Apps. The Patch isn’t failing; the selected record is changing before the Patch finishes, so the formula ends up using the new gallery selection.

    The safest fix is to store the selected customer in a variable first, then use that variable in the Patch instead of Gallery.Selected.

    This way, even if the user clicks another customer immediately, the Patch still updates the correct record.

    Example:

    // OnSelect of the gallery item
    Set(varSelectedCustomer, ThisItem);
    

    Then your Patch should reference the variable, not the gallery:

    Patch(
        'Customer Notes',
        LookUp(
            'Customer Notes',
            CustID = varSelectedCustomer.CustID
        ),
        {
            CustomerNote: txtNote.Text
        }
    );
    

    This alone usually solves the issue.

    If you also want to prevent user interaction while the Patch is running, you can add a simple loading flag:

    Set(varSaving, true);
    
    Patch(
        'Customer Notes',
        LookUp(
            'Customer Notes',
            CustID = varSelectedCustomer.CustID
        ),
        {
            CustomerNote: txtNote.Text
        }
    );
    
    Set(varSaving, false);
    

    Then:

    • Set the gallery DisplayMode to:

    If(varSaving, DisplayMode.Disabled, DisplayMode.Edit)
    
    • Optionally show a spinner or overlay while varSaving = true.

    Why this happens

    Gallery.Selected is not locked at execution time.
    If the user clicks another record before Patch completes, Power Apps evaluates the formula again using the new selection.

    Using a variable creates a snapshot of the selected record, which prevents race conditions.

    Recommended approach

    ✔ Always store selected records in variables
    ✔ Never Patch directly from Gallery.Selected
    ✔ Optionally disable UI during save

    This pattern avoids accidental updates and is widely used in production Power Apps.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Kalathiya Profile Picture

Kalathiya 460

#2
WarrenBelz Profile Picture

WarrenBelz 381 Most Valuable Professional

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 330 Super User 2025 Season 2

Last 30 days Overall leaderboard