web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
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
    Real-Time Stock Synchronization Issue in Multi-User Order Application
    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

Coming soon: forum hierarchy changes

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

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 308 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 222 Super User 2025 Season 2

Last 30 days Overall leaderboard