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 / Patching a sharepoint ...
Power Apps
Answered

Patching a sharepoint item to a collection

(0) ShareShare
ReportReport
Posted on by 276

Hi all,

 

I'm quite average at building powerapps, but one function that gets me a lot of the time is the patch function.  I cant seem to get the following too work, and i've spent hours trying multiple ways and i just cant figure out why its no working.

 

My setup.

I have a gallery named "gallery1_5", this gallery's items property is a collection called "CatalogueSupplier". The collection is Collected from a sharepoint list called "materialsList".

I have the gallery setup so that i can edit the gallery and patch/update the collection ("CatalogueSupplier") and then once happy with the changes the user can then click a confirm button and it then goes and patches the datasource "MaterialsList" with the changes.  This all works fine so my patching skills are somewhat working.

When testing this, I realized that if a mistake was made during the editing process there isnt a way to "Undo", so what i wanted to do was to be able to have another button with the "Undo" icon which would write back the orignal record to the gallery, effectively undoing any changes they had made to that record.

I have tried lots of ways, the way below is what looks correct to me, but nothing will work.  My issue seems to be that the lookup isnt bringing the records through, however when i create a gallery in order to test the lookup with the same lookup code that seems to work.  Its frying my brain and kept me up till 1am last night and i've spent another 2 hours on it today so i've had to succumb to putting my issues on the forum.

Patch(CatalogueSupplier,Gallery1_5.Selected, LookUp(MaterialList, BELREF = ThisItem.BELREF),{CATEGORY:ThisItem.CATEGORY})
Patch(CatalogueSupplier,LookUp(MaterialList, BELREF=ThisItem.BELREF),{CATEGORY:ThisItem.CATEGORY}) 
LookUp(MaterialList, BELREF = ThisItem.BELREF,Patch(CatalogueSupplier,Gallery1_5.Selected,{CATEGORY:ThisItem.CATEGORY}))

 

I have attached some picture of the APP and the Datasource, Collection, and gallery.

the column names in the Datasource "materialList" says Title, but this is usually reference in the app a BELREF which is what the columns name is in the list settings

Hope someone can help and point out my error.

Many thanks in advance,

Screenshot3 - Collection.png
Screenshot 1.png
Screenshot 2.png
Categories:
I have the same question (0)
  • Verified answer
    mmollet Profile Picture
    3,187 on at

    From what I gathered you are currently making a local copy of the SP list so that your user can make changes to it wihtout changing the actual data and then once they are satisfied they can submit them all in one batch. You now want the option to undo any changes made to individual entries. For example they change 10 entries and those entires are patched to SP. They then realise that entry 6 was wrong and so they want to undo the changes they made for that entry. Assuming this is true you could try the following:

     

    Create 2 separate local collections instead of just one. The first is for what you are already using it for, the user making changes etc. The second is just to keep a local record of the values before they were changed. This collection should never be changed as it is essentially your 'restore point' for the items in the collection.

     

    Your undo button for each item would be something like:

    Patch(YourSPList, LookUp(Collection2, ID = ThisItem.ID), {...add fields to fix here...})

    You may be able to just use ThisItem instead of what I have typed in Green in the previous sentence but you will have to test that theory. What this is doing is Patching the record in the actual SP List back to what it was pre change. The user can then choose to change it again if they so choose. 

     

    This 'restore point' will lose its memory and use if the app is closed so keep that in mind. 

  • d3ell Profile Picture
    276 on at

    Hi, 

    Thanks for this.  Your logic is well thought out and whilst it didnt work in the format you sent it, i managed to tweek the code a little bit to add in the gallery1_4.Selected and it works a dream!

    Working code is as below..

    Patch(CatalogueSupplier,Gallery1_4.Selected, LookUp(CatalogueSupplierBackup, ID = ThisItem.ID))

     

    I have accepted yours as a solution,  thanks for your time, much appreciated. 🙂

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

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 352 Most Valuable Professional

#2
11manish Profile Picture

11manish 192

#3
Valantis Profile Picture

Valantis 128

Last 30 days Overall leaderboard