
Announcements
Hi
How could i use patch and insert new records and update existing from a gallery on one go?
Backend DB is dataverse
Hi @jja ,
Patch is pretty cool - if you consider this construct;
Patch(Source, BaseRecords, ChangeRecords)
If BaseRecords = Defaults(Source) then Patch knows to insert a new record with your changerecord info.
If BaseRecords = a single record, (like the result of a lookup to source) then it knows to edit that record with your changerecord info.
If BaseRecords is a table, then it expects it to be a set of records matching your source construct and will look for a corresponding table of changerecords. If you supply a changerecords table, it will use baserecords to identify the existing records in the source, and matching changerecords to update those base records in a batch.
If you don't specify changerecords, it will upsert your baserecords in a batch - which means update if they exist and insert if they don't.
I tested with this example;
ClearCollect(collectBaseRecords, FirstN(myList, 5)); //getting some base records
UpdateIf(collectBaseRecords, true, {Title: "Updated"}); //editing the base records
Collect(collectBaseRecords, {Title: "Inserted1"}, {Title: "Inserted2"}); //adding some new records
Patch(myList, collectBaseRecords) //upserting back to source
You should be able to reuse this logic and apply it to your need.
Kind regards,
RT