cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
johnjohn123
Super User
Super User

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
Super User
Super User

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 Click on the Thumbs Up below. and Accept it as the solution . to help others find helpful.

@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
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

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.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

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