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 ?
Solved! Go to Solution.
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.
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.
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.
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.
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.
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.
Great! I'm glad that UpdateIf solved your problem
Stay up tp date on the latest blogs and activities in the community News & Announcements.
Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST
Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.
User | Count |
---|---|
197 | |
176 | |
62 | |
34 | |
32 |
User | Count |
---|---|
344 | |
272 | |
111 | |
75 | |
59 |