cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
johnjohn123
Post Prodigy
Post Prodigy

How did Patch know that i need to edit a record a not update it

I have a PopUp with only one field >>and a save button >> inside the Save button i have the following formula inside the OnSelect:-

 

Path(ParentTable,Gallery1.Selected, {Quantity: NewQTY.Text});

 

now the Patch will update the related record inside the parent table.. so how did the patch know that i want to edit the Quantity of existing record and that i do not want to create a new record with the passed quantity ?

thanks

7 REPLIES 7
timl
Super User
Super User

Hi @johnjohn123 

If you pass 2 arguments to the Patch function (like in your example), the patch function merges the two records which effectively results in the edit behaviour that you see.

 

To create a new record with the passed quantity, you would need to supply Defaults(DataSource) as the second argument to Patch.

 

There are more details about the merge behaviour in the documentation here:

https://docs.microsoft.com/en-gb/powerapps/maker/canvas-apps/functions/function-patch

 

timl_0-1629573192252.png

 

zmansuri
Super User
Super User

Because you are not writing Defaults keyword which is necessary to make new records. and also you are specifying specific record. That's how it knows that you want to edit and not create

Ramole
Memorable Member
Memorable Member

Hi @johnjohn123 

 

All you have to is from the record your navigating from just onSelect like this code 

 

Editing record onSelect 

 

Set(varItemShipment,ThisItem);
Set(
    varFormModeShip,
    FormMode.Edit
);Navigate(ShipmentFormScreen);

 

New record creating button 

 

Set(varItemShipment,ThisItem);
Set(
    varFormModeShip,
    FormMode.New
);Navigate(ShipmentFormScreen);

 

 

 

 

On the Form Screen add this The Form DefaultMode 

 

varFormModeShip

 

 

Form Item property 

 

 

varItemShipment

 

 

 

Patch button

 

 

Patch(YourListName,varItemShipment,{Quantity: NewQTY.Text});

 

 

Please change the names to field screen names 

Thank you
If this post helps, then please consider Accept it as the solution to help the others and consider giving it a "Thumbs Up."

@zmansuri  can i know what do you mean by "and also you are specifying specific record. " .. for examplw I could specified a record and add it... Is it this correct? i do not think specifying an item means that it will get edited instead of created..

@timl  so can i say that 2 arguments means edit ,,, while 3 arguments means create?

Thanks

timl
Super User
Super User

@johnjohn123 

To clarify, calling Patch with 2 arguments will never add a record to a data source.

Calling Patch with 3 arguments can either create or update an existing record. If the 2nd argument includes a call to the Defaults function, Patch will create a new record. If the 2nd argument specifies an existing record, Patch will update the record.

@timl  is there any official documentation about you statement?

thansk

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 (1,371)