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 / Same ID Autogreation f...
Power Apps
Unanswered

Same ID Autogreation for multiple items

(1) ShareShare
ReportReport
Posted on by 104

hiya, 

 

i have a been building an online store . i have 2 tables, product and orders and the patch creates a new item into the order table when a new item is submitted. 

 

ive being using this code below and it creates an entry for each item However if a user buys more then 2 items, it creates an order id code, twice. How can i update the code so it reflects if there is more then 2 items it uses the same id? 

 

Set(VarID,Coalesce(Max('Order Details', Value(Right('ID ', 4))), 0));
Patch(
'Order Details',
Defaults('Order Details'),
{ 'ID ':"OID" & Text(VarID + 1, "0000"),
Name: GalCheckOut.Selected.Title,
'Product Color': GalCheckOut.Selected.Color,
'Order Size': GalCheckOut.Selected.SIZE,
'Item Total': GalCheckOut.Selected.PRICE,
Qty: GalCheckOut.Selected.QTY,
'Order Total': GalCheckOut.Selected.SUBTOTAL,
'Ordered By': txtCustomerName.Text
}
);Clear(colShoppingCart); Navigate(Welcome)

Screenshot 2023-11-30 015901.png
Categories:
  • M_Ali_SZ365 Profile Picture
    1,110 on at

    Hi @daniellemaree85 ,

    Please Try This And let me know if its work 

    // Generate a unique Order ID
    Set(VarID, Coalesce(Max('Order Details', Value(Right('ID ', 4))), 0) + 1);
    Set(VarOrderID, "OID" & Text(VarID, "0000"));
    
    // Patch each item in the shopping cart with the same Order ID
    ForAll(
     colShoppingCart As ThisItem,
     Patch(
     'Order Details',
     Defaults('Order Details'),
     {
     'ID ': VarOrderID,
     Name: ThisItem.Title,
     'Product Color': ThisItem.Color,
     'Order Size': ThisItem.SIZE,
     'Item Total': ThisItem.PRICE,
     Qty: ThisItem.QTY,
     'Order Total': ThisItem.SUBTOTAL,
     'Ordered By': txtCustomerName.Text
     }
     )
    );
    
    // Clear the shopping cart and navigate to the welcome screen
    Clear(colShoppingCart); 
    Navigate(Welcome);

    ____________________________________________________________________________________________________________________________

    If my post helped, please mark it as Accept as solution to help others find it. A Thumbs Up would also be appreciated if you found it useful. 

    Warm regards,
    Muhammad Ali

     

  • daniellemaree85 Profile Picture
    104 on at

    hiya @M_Ali_SZ365 

     

    im getting an error using the code suggested, see the screenshot

     

     

    patchissue.png
  • daniellemaree85 Profile Picture
    104 on at

    just to add, its only creating 1 item in the record 

    Screenshot 2023-11-30 033922.png

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 405 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 368

#3
WarrenBelz Profile Picture

WarrenBelz 244 Most Valuable Professional

Last 30 days Overall leaderboard