web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patch for new and upda...
Power Apps
Answered

Patch for new and update records

(0) ShareShare
ReportReport
Posted on by 820

Hi

How could i use patch and insert new records and update existing from a gallery on one go?

Backend DB is dataverse

Categories:
I have the same question (0)
  • Verified answer
    RusselThomas Profile Picture
    4,014 on at

    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

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Kalathiya Profile Picture

Kalathiya 402

#2
WarrenBelz Profile Picture

WarrenBelz 380 Most Valuable Professional

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 293 Super User 2025 Season 2

Last 30 days Overall leaderboard