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 Platform Community / Forums / Power Apps / Patch not working to U...
Power Apps
Answered

Patch not working to Update a record in a local collection

(0) ShareShare
ReportReport
Posted on by 8

Hey Guys, Im having issues when I'm trying to update a record in a local collection 'MileageCache' using the patch function. The strange thing is the code works fine updating the sharepoint list directly.

 

I am wanting to update a local collection of the sharepoint list so adding records works fine when offline.

 

Here is the code im using, like I say it works fine with the online sharepoint list directly:

 

 UpdateContext(
 {
 tempMileageItem: First(
 Filter(
 MileageCache,
 ID = MileageItem.ID
 )
 )
 }
 );

 Patch(
 MileageCache,
 tempMileageItem,
 Patch(
 tempMileageItem,
 {
 'End Mileage': Value(MileageText.Text),
 'End Date': Now(),
 'End Location': Location.Latitude & "," & Location.Longitude
 }
 )
 )

The global variable MileageItem is a single record from MileageCache and is set by:

 

 Set(
 MileageItem,
 Patch(
 MileageCache,
 Defaults(MileageCache),
 {
 'ID':100,
 'Start Mileage': Value(MileageText.Text),
 'Start Date': Now(),
 'Start Location': Location.Latitude & "," & Location.Longitude
 }
 )
 )

Does anyone have any ideas why I am unable to update the record in the collection using the Patch function ?

Categories:
I have the same question (0)
  • Verified answer
    timl Profile Picture
    36,415 Super User 2025 Season 2 on at

    Hi @henda79 

    The Patch function can be buggy, especially when local collections and null values are involved.

    Here's an example of what I mean.

    https://powerusers.microsoft.com/t5/General-Discussion/Patch-not-updating-on-null-values-in-database-tables/td-p/92003

    If you just want to update a record in your MileageCache collection, you could consider the use of the UpdateIf function rather than Patch, as from my experience, this tends to work more reliably in these types of circumstances.

  • henda79 Profile Picture
    8 on at

    Ok, I'll give it a whirl and let you know.

     

    I thought its was a issue with Patch as I had spent several hours trying to "debug" the issue, but since you can't debug, issues like this take forever to work out.

     

    Thanks.

  • henda79 Profile Picture
    8 on at

    thanks @timl , using UpdateIf rather than Patch works fine.

    It seems that Patch works OK to insert the initial record but it seems to fail for the update with a collection but not for an online source.

  • timl Profile Picture
    36,415 Super User 2025 Season 2 on at

    Great! I'm glad that UpdateIf solved your problem

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…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard