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 Items from Galle...
Power Apps
Unanswered

Patch Items from Gallery to Sharepoint List

(1) ShareShare
ReportReport
Posted on by

Hello together,

 

at the moment I am working on a PowerApp for inventory management.

I have a sharepoint list "Electrical components" as  datasource where all existing electrical components are stored.

 

In powerapps i created a gallery (Gallery 1), which acts as a "shopping cart" for the warehouseman. The items in Gallery1 are Collection "colShoppingcart" When he gets an order he should go to this screen and add the corresponding nuber of components needed to the "shopping cart".

When he is done he should click on a button to submit the removal from stock.

Here is the point, where I need the patch function:

I need the Sharepoint List to update the stock for all items that where removed from the warehouse.

So I need a function for the On-Select of my submit button.

Can anyone help me with a function that works on my case?

Thanks a lot!

Categories:
I have the same question (0)
  • KeithAtherton Profile Picture
    3,705 Most Valuable Professional on at

    Hi @luwu_7100,

     

    I suggest breaking the problem down into manageable logic steps such as the following, then tackle each step separately:

     

    • For each record in collection colShoppingcart, get identifier (e.g. ComponentID) and quantity (e.g. Quantity) to deduct
    • Update the data source ("Electrical components" SharePoint list)
      • Lookup list record where list.ComponentID = colShoppingcart.ComponentID
      • Set list.Quantity = list.Quantity - colShoppingcart.Quantity

     

    Also, when it comes to updating the "Electrical components" SharePoint list, this could be done either row-by-row or by a single multi-update call (which is usually faster).

     

    This article provides a good examples of updating multiple records: https://www.matthewdevaney.com/patch-multiple-records-in-power-apps-10x-faster/


    If I have answered your question, please mark your post as Solved.
    If you like my response, please give it a Thumbs Up.
    Follow me online.

  • Verified answer
    WiZey Profile Picture
    3,023 Moderator on at

    Hello @luwu_7100 ,

     

    You'll need both "ForAll()" and "Patch()" in your case.

     

    "Patch()" will help you update the record's columns in your list, while "ForAll()" will call "Patch()" for each item in your gallery.

     

    To update an existing record, "Patch()" needs three parameters:

    • The datasource
    • The record to update
    • The updates to apply
    With({_record:LookUp(datasource, ID = ThisItem.ID)},
    Patch(
     datasource,
     _record,
     {
     Stock = _record.Stock - ThisItem.Stock
     }
    )

     

    With "LookUp()", you extract the record from the list so "Patch()" can recognize which record to update. It also helps to subtract the current stock with the submitted amount.

     

    Then, you call "Patch()" for each item of your gallery with "ForAll()".

    ForAll(
     Gallery.AllItems,
     With({_record:LookUp(datasource, ID = ThisRecord.ID)},
     Patch(
     datasource,
     _record,
     {
     Stock = _record.Stock - ThisRecord.Stock
     }
     )
     )
    )

     

    You can also add some condition before patching, like testing if the stock will turn out negative after the subtract.

     

    Hope this was helpful to you.

     

     

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 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard