cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Patch a collection with items inputted in a Gallery of the same collection

Hello, 

 

I am doing an application for adding products to a cart for then being able to quote them. I want users to be able to apply discounts on their items and then being able to calculate a final price. 

 

When items are added to the cart, the columns "Discount" and "FinalPrice" are added with a price of 0.

 

I would like a button that when users enter a discount value inside each item within a gallery, the final price and discount could be saved back to the collection items. 

 

For example: 

 

image.pngI would like that when the users input a discount, like [50], and click on apply, the final price for the first item to be of 2300.

 

And with the same apply action the final price of the second item to remain as the list price 2300 because of a discount of 0.

 

 

 

 

 

 

 

 

 

Currently I try it with the formula: 

Patch(Courses_Package_Collection,Defaults(Courses_Package_Collection),{Discount: Value(Unitary_discount_input.Text),FinalPrice: ListPrice - (ListPrice * Unitary_discount_input)})

Of course nothing good happened... first because the ListPrice Value I want to use that is a value already from the collection gives and error. And second this would just create another item in the collection, it wouldn't edit nothing. 

 

Please help!!

1 ACCEPTED SOLUTION

Accepted Solutions
Drrickryp
Super User
Super User

Hi @Anonymous 

The Patch() function contains three elements, the datasource being patched, the record being patched, and the fields in that record being patched. 

To add a NEW record to the datasource (this could be a SharePoint list or a Collection), you use Defaults(datasource) as the second element.  Defaults() means that a new record is being added. 

To patch an existing record from within the gallery, you would use 

 

Patch(Courses_Package_Collection,ThisItem,{...

 

as the OnSelect property of an icon inside of the gallery.

 To patch an existing record selected inside the gallery but from an icon outside of the gallery, you would use

 

Patch(Courses_Package_Collection,Lookup(Courses_Package_Collection,ID=Gallery1.Selected.ID),{...

 

as the OnSelect property of that icon.

  

View solution in original post

3 REPLIES 3
Drrickryp
Super User
Super User

Hi @Anonymous 

The Patch() function contains three elements, the datasource being patched, the record being patched, and the fields in that record being patched. 

To add a NEW record to the datasource (this could be a SharePoint list or a Collection), you use Defaults(datasource) as the second element.  Defaults() means that a new record is being added. 

To patch an existing record from within the gallery, you would use 

 

Patch(Courses_Package_Collection,ThisItem,{...

 

as the OnSelect property of an icon inside of the gallery.

 To patch an existing record selected inside the gallery but from an icon outside of the gallery, you would use

 

Patch(Courses_Package_Collection,Lookup(Courses_Package_Collection,ID=Gallery1.Selected.ID),{...

 

as the OnSelect property of that icon.

  

Anonymous
Not applicable

That worked perfectly.

Kind regards from my beautiful Costa Rica!!

Drrickryp
Super User
Super User

You are quite welcome.You are quite welcome.

 

 

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (1,650)