cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Beowulf_Agat
Frequent Visitor

Patch datasource with value from collection

Hi,

 

I'm building an app based on the shopping cart tutorial by Shane Young. (https://www.youtube.com/watch?v=Ztn39KuOW0g)

The items in this web store has a limited quantity and I want the number of items available to update dynamically when changing the number of items in the shopping cart.

 

The data is stored in a sharepoint list called "Products"

 

So... I have a label for quantity in stock with the following code for Text: "Quantity: " & ThisItem.qty

I also have a slider for each item set to Max: ThisItem.qty

Then when you add something to the shopping cart (the plus sign) I use the following code for OnSelect: Collect(colShoppingCart; {Title: ThisItem.Title; Manufacturer: ThisItem.Manufacturer; Qty: Slider1.Value});;Patch(Products; ThisItem;{'Qty in stock': ThisItem.'Qty in stock' - Slider1.Value}) - This works well. When adding items to the cart, the value of items in stock updates correctly.

 

Now to my problems. If you remove items from the cart (code for this is: Remove(colShoppingCart; ThisItem) ) they are removed from the collection BUT I also want the value for quantity in stock to change. I need to pull the value for this item from the collection and add it to the value of items in stock for that same item. That is, I need to patch my datasource (Products) with the current value + the value from the collection.

 

So to cut a long story short: Is there a way to add a value from a collection back to its original datasource?

 

Beowulf_Agat_0-1616062350075.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-jefferni
Community Support
Community Support

Hi @Beowulf_Agat ,

 

Would you like to deduct the amount of item added into the shopping cart collection from total inventory, and restore the total inventory if removing item from the collection?

 

If so, since you have already leveraged a Patch function on the plus icon to deduct slider value from inventory quantity, it would be easy for you to understand that another Patch function on the trash icon be used to restore the inventory quantity. But first, you will need to add the deducted quantity into the collection as well.

 

So, please follow the steps below:

1\ Add a column in the collection to include deducted quantity:

Collect(colShoppingCart; {Title: ThisItem.Title; Manufacturer: ThisItem.Manufacturer; Qty: Slider1.Value; remQty:'Qty in stock' - Slider1.Value });;Patch(Products; ThisItem;{'Qty in stock': ThisItem.'Qty in stock' - Slider1.Value})

 

2\ Add a Patch function OnSelect of the trash icon to update data source:

Remove(colShoppingCart; ThisItem);
Patch(Products; LookUp(Prodcts, Title = ThisItem.Title);{'Qty in stock': ThisItem.'Qty in stock'+ThisItem.remQty})

 

But IMO, a better approach could be: adding a column let's say "Quantity Available" to store the quantity that total storage minus the quantity in the shopping cart. Why doing this? This will help keep the inventory clear, not only to warehouse managers but also to App users.

 

Hope this helps.

 

Best regards,

Community Support Team _ Jeffer Ni
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

3 REPLIES 3
v-jefferni
Community Support
Community Support

Hi @Beowulf_Agat ,

 

Would you like to deduct the amount of item added into the shopping cart collection from total inventory, and restore the total inventory if removing item from the collection?

 

If so, since you have already leveraged a Patch function on the plus icon to deduct slider value from inventory quantity, it would be easy for you to understand that another Patch function on the trash icon be used to restore the inventory quantity. But first, you will need to add the deducted quantity into the collection as well.

 

So, please follow the steps below:

1\ Add a column in the collection to include deducted quantity:

Collect(colShoppingCart; {Title: ThisItem.Title; Manufacturer: ThisItem.Manufacturer; Qty: Slider1.Value; remQty:'Qty in stock' - Slider1.Value });;Patch(Products; ThisItem;{'Qty in stock': ThisItem.'Qty in stock' - Slider1.Value})

 

2\ Add a Patch function OnSelect of the trash icon to update data source:

Remove(colShoppingCart; ThisItem);
Patch(Products; LookUp(Prodcts, Title = ThisItem.Title);{'Qty in stock': ThisItem.'Qty in stock'+ThisItem.remQty})

 

But IMO, a better approach could be: adding a column let's say "Quantity Available" to store the quantity that total storage minus the quantity in the shopping cart. Why doing this? This will help keep the inventory clear, not only to warehouse managers but also to App users.

 

Hope this helps.

 

Best regards,

Community Support Team _ Jeffer Ni
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

Hi @v-jefferni ,

 

Thanks, this worked out well. However I stumbled upon another issue that I am unable to figure out. 

If a user puts, say 4 items of the same kind in the shopping cart, these are stored in the collection. And if the user adds more of the same item the collection is patched.

 

My trouble is that in order to patch the collection I have a column in my SP list called 'Qty in cart' so when adding more items of the same type I do (from the gallery using my SP-list): 

 

Patch(colShoppingCart;LookUp(colShoppingCart;ID = ThisItem.ID);
{
QtyCart: ThisItem.'Qty in cart' + Slider1.Value;
QtyStock: ThisItem.'Qty in stock' - Slider1.Value
})

 

Now this works great but since *Quantity in cart" is stored in my SP-list, it will affect everyone using the app, and potentially mess up their quantity.

 

I would like to store 'Quantity in cart' in my collection instead (or som other way so it only affects a specific user) so that it doesn't mess up my SP-list. 

Any ideas? Feels like I've tried everything.

Hi @Beowulf_Agat ,

 

Actually I would say I prefer your earlier scenario, since it would be telling users the available quantity of a product for them to add into shopping cart, which is Qty in stock minus Qty in cart, in case the total quantity of a product in all shopping carts exceeds the quantity in the stock.

 

Anyway, you'd better post a new thread with the updated scenario and details so that all other users in this forum would be able to see it and help you.

 

Best regards,

Community Support Team _ Jeffer Ni
If this post helps, then please consider Accept it as the solution to help the other members find it.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,749)