Skip to main content

Notifications

Power Apps - Power Apps Pro Dev & ISV
Suggested answer

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

Posted on by 7
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});
 
  • Suggested answer
    jpespena Profile Picture
    jpespena 294 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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,591

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,090

Leaderboard