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 / 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)
  • Verified answer
    ronaldwalcott Profile Picture
    3,847 Super User 2025 Season 2 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.
  • lbendlin Profile Picture
    8,540 Super User 2025 Season 2 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.

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
Kalathiya Profile Picture

Kalathiya 421

#2
WarrenBelz Profile Picture

WarrenBelz 365 Most Valuable Professional

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 339 Super User 2025 Season 2

Last 30 days Overall leaderboard