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})
Solved! Go to Solution.
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})
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! |
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! |
yes, there is a field with a primary key (not listed here) , the customer ID.
And this was patched by the app, too.🙈
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
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})
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! |
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.
User | Count |
---|---|
253 | |
106 | |
94 | |
50 | |
39 |