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 / Real-Time Stock Upate ...
Power Apps
Answered

Real-Time Stock Upate Issue in Multi-User Order Application

(1) ShareShare
ReportReport
Posted on by 6
Hi guys i have some issue in my  orders app in updating the  multiple stock values.Let me explain my issue.
  • Initial State:
    • Stock for "Apples" is 10 in the Products table.
    • Two users, User A and User B, place orders at the same time:
      • User A orders 6 apples.
      • User B orders 5 apples.
  • Problem:
    • Without synchronization, both users might see the initial stock as 10.
    • Orders might process independently, resulting in overselling (6 + 5 = 11) when the stock should only allow up to 10 apples.
  • Expected Behavior:
    • If User A confirms their order first, the stock should update to 4.
    • User B should only be able to order up to 4 apples.
    • If User B tries to order 5 apples after User A’s order, the app should prevent it.
This is my code

Set(myorder,orderid.Run().orderid);

Patch(

    Orders,LookUp(Orders,Title=myorder),

    {

        'Item Count': Value(Label21.Text),

        'Total Amount': Value(Label9.Text)

    }

);

ForAll(

    Gallery2.AllItems,

    Patch(

        'product Items',

        Defaults('product Items'),

        {

            Title: ThisRecord.Label5.Text,

            Quantity: ThisRecord.Label6.Text,

            Amount: ThisRecord.Label7.Text,

            'Order ID':{Value:"",Id:LookUp(Orders,Title=myorder,ID)}

        }

    )

);

ForAll(

    Gallery2.AllItems,

    Patch(

        Products,LookUp(Products,Title=Label5.Text),{Stock:Value(ThisRecord.Label6_1.Text)})

);

 

Refresh(Products);

UpdateContext({varplace:true});

I have the same question (0)
  • lbendlin Profile Picture
    8,626 Super User 2026 Season 1 on at
    And this is a conflict between just two people! Imagine rolling that out to 20 or more...
     
    You need to drastically increase the refresh frequency, and include a refresh as the first part of the order placement code. But even then there is no guarantee that your latency is low enough to avoid situations like you describe.
  • Verified answer
    ronaldwalcott Profile Picture
    3,862 Moderator on at
    This is a classic issue and in other programming solutions was solved by essentially locking the record for updates.
    Other ways to solve this are
    - show a low stock message before the order is completed (this manages expectations and will allow you to cancel an order if the product count goes negative)
    - continually check the stock using a timer
    - check the stock before performing the update
    - check the stock after performing the update (to adjust the order if necessary)
    - you could simulate a record lock for updates but I don't know how much delay that would add to the ordering update process.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 509 Most Valuable Professional

#2
Haque Profile Picture

Haque 302

#3
11manish Profile Picture

11manish 265

Last 30 days Overall leaderboard