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 Synchr...
Power Apps
Suggested Answer

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

(3) ShareShare
ReportReport
Posted on by 10
Hi guys, I am working on order application, stock values are not updating correctly across sessions when multiple users place orders for the same item simultaneously. We need a solution to synchronize stock updates in real-time, ensuring accurate availability and preventing overselling.Can you guys please help me with this problem.
 
And here is my code:
 
ClearCollect(myapplica,
 
ForAll(
    Gallery2.AllItems,
    LookUp(Products,ID=ThisRecord.ID
));



 
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)
  • Suggested answer
    jpespena Profile Picture
    335 on at
    Hi,
     
    Try adding another Refresh() function before the ClearCollect() function to get first the current data before executing new orders. Like:
     
    Refresh(Products);
    
    ClearCollect(myapplica,
     
    ForAll(
        Gallery2.AllItems,
        LookUp(Products,ID=ThisRecord.ID
    ));
    
    
    
     
    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});
     

    If my post helped resolve your issue, please click Accept as Solution—this helps others find it more easily and marks the item as closed. If you found this or my previous reply helpful, a Like would also be 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

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

#2
Haque Profile Picture

Haque 206

#3
Kalathiya Profile Picture

Kalathiya 201 Super User 2026 Season 1

Last 30 days Overall leaderboard