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

Patch without Lookup, how can this work - i'm confused

Hi,

i just reviewed some code, i wrote in the beginning of my power apps career and now im confused how that code can work properly.

Im patching a MYSQL database (adr_de) with data from a editform. The editform gets its data from a collection, that is filled with data from the mysql database adr_de.

Im writing my changes back to the collection and patch the mysql database.

First, the following code works, even though there is no lookup for the specific record?!

:

 

//Update Collection
SubmitForm(formKundeEditieren);;
//Update adr_de
Patch(
    '[Abrechnung].[adr_de]';
    {ADR_DE_EGZH_LETZTER_BESUCH: DatePickerLetzterBesuch.SelectedDate};
    {ADR_DE_EGZH_NOTIZ: txtNotiz.Text};
    {ADR_DE_FINAME1: txtFirma.Text};
    {ADR_DE_FINAME2: txtName.Text};
    {ADR_DE_STR: txtStrasse.Text};
    {ADR_DE_ORT: txtOrt.Text};
    {ADR_DE_TELEFON: txtTelefon.Text};
    {ADR_DE_TELEFON2: txtHandy.Text};
    {ADR_DE_MAIL: txtMail.Text};
    {ADR_DE_EGZH_ER_ZK: dropER_ZK.Selected.Value};
    {ADR_DE_EGZH_LKV_MGL: dropLKV.Selected.Value})

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Ok, so did some testing,

 

The reason is that it is using the first parameter as a lookup when you specify multiple records separated by ; (for your language setting, for others it would be , )

 

It is the same as:

 

 

Patch(
    '[Abrechnung].[adr_de]';
    LookUp('[Abrechnung].[adr_de]'; ADR_DE_EGZH_LETZTER_BESUCH = DatePickerLetzterBesuch.SelectedDate);
    {ADR_DE_EGZH_NOTIZ: txtNotiz.Text};
    {ADR_DE_FINAME1: txtFirma.Text};
    {ADR_DE_FINAME2: txtName.Text};
    {ADR_DE_STR: txtStrasse.Text};
    {ADR_DE_ORT: txtOrt.Text};
    {ADR_DE_TELEFON: txtTelefon.Text};
    {ADR_DE_TELEFON2: txtHandy.Text};
    {ADR_DE_MAIL: txtMail.Text};
    {ADR_DE_EGZH_ER_ZK: dropER_ZK.Selected.Value};
    {ADR_DE_EGZH_LKV_MGL: dropLKV.Selected.Value})

 

 

Patch(datasource; {recordToLookUp: recordToLookUpValue}; {update1: update1}; {update2: update2})

iAm_ManCat_0-1669979943802.png

 

So I would highly recommend add the customerID as your first field using something like 

 

 

{customerID: formKundeEditieren.LastSubmit.customerID}

 

 

as there may come a day when the dates are duplicated and it would patch the first available record it looks up with that date.

@iAm_ManCat


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


View solution in original post

5 REPLIES 5
iAm_ManCat
Super User
Super User

Are any of those columns in your patch a primary key?

@iAm_ManCat


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


SteMat
Frequent Visitor

yes, there is  a field with a primary key (not listed here) , the customer ID.

And this was patched by the app, too.🙈

SebS
Memorable Member
Memorable Member

@SteMat 

 

I believe it's same as You patch Database with Collection Patch("DataSource",Collection) patch will find its way even it's not intended future.

 

You said you patching EditForm mean this Form contain ThisItem even if You don't manage this in the code, I bet patch manage it for you so probably another not intended future of the patch but good to know 🙂

 

Check the collection if it does not contain some additional Reference column what's added cause You collect direct from form what Patch may use as Lookup later on without You knowing it


If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users to find it.

Ok, so did some testing,

 

The reason is that it is using the first parameter as a lookup when you specify multiple records separated by ; (for your language setting, for others it would be , )

 

It is the same as:

 

 

Patch(
    '[Abrechnung].[adr_de]';
    LookUp('[Abrechnung].[adr_de]'; ADR_DE_EGZH_LETZTER_BESUCH = DatePickerLetzterBesuch.SelectedDate);
    {ADR_DE_EGZH_NOTIZ: txtNotiz.Text};
    {ADR_DE_FINAME1: txtFirma.Text};
    {ADR_DE_FINAME2: txtName.Text};
    {ADR_DE_STR: txtStrasse.Text};
    {ADR_DE_ORT: txtOrt.Text};
    {ADR_DE_TELEFON: txtTelefon.Text};
    {ADR_DE_TELEFON2: txtHandy.Text};
    {ADR_DE_MAIL: txtMail.Text};
    {ADR_DE_EGZH_ER_ZK: dropER_ZK.Selected.Value};
    {ADR_DE_EGZH_LKV_MGL: dropLKV.Selected.Value})

 

 

Patch(datasource; {recordToLookUp: recordToLookUpValue}; {update1: update1}; {update2: update2})

iAm_ManCat_0-1669979943802.png

 

So I would highly recommend add the customerID as your first field using something like 

 

 

{customerID: formKundeEditieren.LastSubmit.customerID}

 

 

as there may come a day when the dates are duplicated and it would patch the first available record it looks up with that date.

@iAm_ManCat


Please 'Mark as Solution' if someone's post answered your question and always 'Thumbs Up' the posts you like or that helped you!


Thanks!
You and everyone else in the community make it the awesome and welcoming place it is, keep your questions coming and make sure to 'like' anything that makes you 'Appy
Sancho Harker, MVP


SteMat
Frequent Visitor

Actually, the customer number is the first field, i just didnt want to post it here due data security reasons.

But thats a interesting case, because it looks like the lookup function is not necessary

for patching a specific record.

Well anyway, it's not a good idea to patch a primary key in a database 🙂

Thanks for your clarification.

 

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

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