cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ChrisEluva
New Member

Auto generate the default value for a field in a gallery and patch this to a collection

I have a collection called 'ItemCollection' with fields like itemid, ItemLabourTime (this is the time required to manufacture an item), Labour(i.e TotalLabour, based on quantity entered) and several other fields.
I'm trying to read in the value for quantity from the user in a gallery(see screenshot below) and auto-generate the field Labour based on the value entered by the user.

ChrisEluva_0-1638389310832.png


So if a item has ItemLabourTime of 10 mins and the user enters 2 for quantity,  the labour value (i.e TotalLabour) for that item in the gallery should be 20.
I was trying to use the following formula to patch a default value for Labour to the collection -
Patch(ItemCollection, ThisItem,{Labour: ThisItem.ItemLabourTime*ThisItem.quantity})
but that was giving me an error- 'behavior function in a non behavior property'.

The plan was to set this as default and use an update in the Onchange value if the user wants to reset the auto generated value.


How can I achieve this functionality? Any help is much appreciated.

10 REPLIES 10
WarrenBelz
Super User
Super User

Hi @ChrisEluva ,

Try

Patch(
   ItemCollection, 
   ThisItem,
   {Labour: Value(ItemLabourTime.Text)*ThisItem.quantity}
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

Sorry, that's not working. Still giving the same error.

@ChrisEluva ,

Where are you running the code from? To use ThisItem it must be from within the gallery. I also assume ItemLabelTime is the Text box.

BoHamad
Helper I
Helper I

For labour text box in the Text property 

use this formula Value(ThisItem.quantity)*Value(ThisItem.ItemLabourTime)

But, to patch the values to the collection I recommend to add a button to save the data for all gallery or for a single record. Because it doesn’t make sense if u want to patch the values every time when the user change the value 

 

hope this helps u

@WarrenBelz Yes I'm using it within the gallery.
ItemLabelTime is not the text box, it is the predefined time required per item. The user enters the quantity and the app should generate the highlighted "Labour"(TotalLabour) field. i.e Quantity * ItemLabelTime(for that item in the gallery)
The only reason I have the input box (text box) is to read in any changes to the automatically calculated time.

Btw, appreciate you looking into this!

Hi @ChrisEluva ,

If ItemLabelTime is not a control, I assume it is a field in your source data List - what type of field is it?

Yes, it is a field in my source. My source is a SharePoint list and ItemLabelTime  is of type number. 

@ChrisEluva ,

Only one thing left then - the quantity is entered by the user?

Patch(
   ItemCollection, 
   ThisItem,
   {Labour: ThisItem.ItemLabourTime * Value(QuantityTextBoxName.Text)}
)

Replace with your text box name

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

Unfortunately still returning the same error! 

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,851)