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 / Updating SharePoint list
Power Apps
Answered

Updating SharePoint list

(0) ShareShare
ReportReport
Posted on by 14

Hi,

 

Im pretty new to Powerapps but i have got the hang of some things and have managed to create an App based on fields within a sharepoint list.  

 

The user will check out these items and place them in a shopping cart and then process the order.  This is an internal system so no actual money gets exchanged.

 

Im stuck on one thing that i think should be simple.  When the user checks out the shopping cart ( this is a collection) i want to be able to update the existing list with how many items are remaning in stock.  For example, A user want 2 folders and 3 pens.  There is currently 5 of each in stock.  The user adds 2 folders and 3 pens to the cart and checks them out.  I want power apps to go back to the sharepoint list that the data is being read from and deduct 2 folders and 3 pens  so that folders now say 3 and pens say 2.

 

Can some one point me in the right direction?

 

Thanks,


Josh

 

Categories:
  • aprildunnam Profile Picture
    704 on at

    Could you share how your SharePoint list is set up (the columns, sample data, etc)?  

  • Jyoung Profile Picture
    14 on at

    Hi Aprildunnam,

     

    Thanks for your reply.  The list is very simple:

     

    Title (which is essentialy the Item Name)

    Stock Used

    Stock Remaining.

     

    Thanks,

     

    Josh

  • aprildunnam Profile Picture
    704 on at

    This would be a good use case for a Flow.  I've did this with one of my PowerApps.  You could follow the directions to Start a Flow from a PowerApp here:

     

    https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/using-logic-flows  

     

    In your PowerApp you'll need to use the ForAll() function to loop through your collection and then run your Flow and pass the parameters to update the list item.  

  • Jyoung Profile Picture
    14 on at

    Thanks,

     

    I actually dont know how i would use the flow to do this.. Ive loked at various blogs etc but i cant make sense of it... perhaps i just need a nap.

     

    Without spending too much time could you give me a little but more info?

     

    Thanks 🙂

     

     

  • Verified answer
    aprildunnam Profile Picture
    704 on at

    So I thought about your use case a little more and I think you could accomplish what you're needing with a simple Patch statement.  I did a quick test on my environment and that seemed to work.  I have a collection of items and I added a submit button with the following function:

     

    ForAll(ShoppingCart,Patch(InventoryTest,First(Filter(InventoryTest, ID in ShoppingCart.ID)),{StockRemaining: StockRemaining - 1},{StockUsed: StockUsed +1}));Clear(ShoppingCart)

    So first, I'm using ForAll to loop through all items in my collection.  Then I'm using the Patch statement which lets you add items to SharePoint.  I'm passing in the name of my data source (the SharePoint list) and then I'm using the First and Filter functions to make sure I'm getting the current item to update.  Then I'm taking my stock remaining and subtracting 1 and taking stock used and adding 1.  

     

    I hope this helps!

    Screen Shot 2018-04-12 at 1.56.19 PM.png
  • Jyoung Profile Picture
    14 on at

    Thanks April,

     

    I think i am closer than ever.  For testing purposes i am using this.

    ForAll(ShoppingCart,Patch(Stationary,First(Filter(Stationary, ID in ShoppingCart.ID)),{Used:1}))

    However it tells me that ID on the left side of the in operator cannot be converted to a control.  There is no error in the code just a blue dot.

     

    I tried to execute the code but still the list does not get updated.

     

    Any further advice would be much appreciated 🙂

     

    Thanks,

     

    Josh 

     

  • aprildunnam Profile Picture
    704 on at

    Hmmm.  Have you tried using = instead of in?  Is there any way you could share some screenshots on how your app and data source is configured to give me a little more to go on?

  • Jyoung Profile Picture
    14 on at

    No problem.

     

    Attached are the screen shots:

     

    I have a sharepoint list called stationary.  Inside that are 4 columns:

     - Item ( Text)

     - Required Stock ( Number)

     - Used (Number)

     - Stock on Hand (Calucalted [Required Stock - Used])

     

    At present i have a gallery in power apps that reads Item, Stock on Hand, and ID from from the sharepoint list.   A user clicks on the item and they use a slider to determine how many of that stock they need.  They then add it into a collection called ShoppingCart.

     

    Collect(ShoppingCart, {ItemType:GalleryStationary.Selected.Title1,OrderQuantity:Slider1.Value,ID:GalleryStationary.Selected.Body1});Navigate('Browse Screen',ScreenTransition.Cover)

     

    Fron there they click on the cart and go to the cart screen Where they review the items and then submit the changes.

     

    Hope this helps.  Let me know if you need more info

    add to cart.PNG
    gallery.PNG
    Sharepoint List.PNG
  • aprildunnam Profile Picture
    704 on at

    Unless I'm missing something it looks like in your ShoppingCart Gallery you are passing in "Body1 as the ID instead of the ID of the item.  This would cause the data mismatch error you're getting because you are trying to compare a number to a text value.

  • Jyoung Profile Picture
    14 on at

    Yes your absolutly right... rookie mistake.

    Now it works... sort of.  If i put multiple items into the cart it will only return the first item but put the last item values in the first item.

     

    eg.  I have added 4 folders and 3 pens to the cart  I push the submit button.    In the sharepoint list i see 3 folders used ( not 4)  the pens value is still NULL.  ive gone though the code to the nth degree and it makes sense.... i think

    ForAll(ShoppingCart,Patch(Stationary,First(Filter(Stationary, ID in ShoppingCart.ID)),{Used:OrderQuantity}))

     

    Also the Used:Used+ OrderQuantity or even Used:Used + 1 does not work.  It says the second "used" is invalid.

     

     Josh

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 July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 395 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 260 Most Valuable Professional

Last 30 days Overall leaderboard