Hi all,
building a shopping chart app using x3 separate cds tables, one for orders, one for items available and one for stock available.
I have worked out how to removed stock from my CDS table as I add stuff into my cart (cart being a collection displayed in a gallery) but in reality, I would not want to remove the stock until the order had been placed, so I am trying to create a Forall patch that takes each item in the shopping cart collection and removes from the stock table.
this is how I am removing stock individual a new collection item is added :
UpdateContext({ toUpdate: LookUp('Available Stocks', 'Item Name' = ThisItem.'SRN Reference') }); Patch('Available Stocks', toUpdate, { 'Stock Available': toUpdate.'Stock Available' - Dropdown1.Selected.Value });
Collect(ShoppingBasket, {itemname:Gallery1.Selected.'Item Name', Size:Gallery1.Selected.Size, SRN:Gallery1.Selected.'SRN Reference', PPEtype:Gallery1.Selected.'PPE Type', Img:Gallery1.Selected.Image, QYT:Dropdown1.Selected.Value})
my available stock (item name) and SRN Reference match up which is how I return the record, however when I try this using a button outside of the gallery (unable to use thisItem) I am using this :
UpdateContext({ toUpdate: LookUp('Available Stocks', 'Item Name' = First(ShoppingBasket.SRN).SRN)}) ;
ForAll(ShoppingBasket, (Patch('Available Stocks', toUpdate, { 'Stock Available': toUpdate.'Stock Available' - 1})));
When I use this it only takes the stock off the first item in the shopping cart, not all items..I guess this is something to do with the fact I am using first in my lookup? but cant see another way around this for CDS as if I remove the first I get an error (record returned not text)
any guidance or help would be much appreciated..
thank you.
Solved! Go to Solution.
You shouldn't need the UpdateContext variable. I think this will do it.
ForAll(
ShoppingBasket As sb,
Patch('Available Stocks',
LookUp('Available Stocks', 'Item Name' = sb.SRN),
{ 'Stock Available': sb.'Stock Available' - 1}
)
);
Note: I've assumed your code works for CDS because I cannot check this as I don't use it.
You shouldn't need the UpdateContext variable. I think this will do it.
ForAll(
ShoppingBasket As sb,
Patch('Available Stocks',
LookUp('Available Stocks', 'Item Name' = sb.SRN),
{ 'Stock Available': sb.'Stock Available' - 1}
)
);
Note: I've assumed your code works for CDS because I cannot check this as I don't use it.
that's perfect, thank you mate.
No worries mate
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
User | Count |
---|---|
208 | |
97 | |
60 | |
51 | |
51 |
User | Count |
---|---|
255 | |
158 | |
87 | |
79 | |
62 |