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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / When Using Patch - is ...
Power Apps
Answered

When Using Patch - is there an edit mode?

(0) ShareShare
ReportReport
Posted on by 514

I know when using forms there is a property which can be set to edit or new form.

Is there a way when not using forms and using the Patch command, of testing for a new or an edit record?

I am trying to use the same screen for both adding records or editing existing ones.

At the moment I am setting a variable to either 'New' or 'Edit' values and checking that when I enter the screen.

Wondered If there is a better way.

 

Thank you

Categories:
I have the same question (0)
  • Pstork1 Profile Picture
    69,657 Most Valuable Professional on at

    There isn't a way to have Patch test to see if a record exists and create a new one if it doesn't.  But there are two different syntax forms for using patch for a new record versus an existing record.  The second parameter of the patch statement to create a new record is always defaults(datasourcename) and the second parameter of the patch statement to edit an existing record is some formula that will select a specific record to be updated.  This is usually a Lookup().  What you can do is embed both forms of the Patch in an IF() statement that checks your New/Edit variable to see which statement to execute.  Normally, even if you want to use the same screen and form you pre-populate the form with either default values (new) or existing values (edit).  So you still need to know whether its a new or exisiting record long before you get to patch.

  • Verified answer
    Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    Hi @sienna28 ,

    The patch function is different if one is editing a record rather than adding a new one with respect to the second argument of the function.  In the case of adding a new record it is

    Patch( Customers, Defaults( Customer ), { Name: “Contoso” } ).

      This syntax creates a new record.  In the case of patching an existing record, instead of Defaults(), you specify the record being patched ie. 

    Patch( Customers, Lookup( Customers, Name = "Contoso" ) , { Phone: “1-212-555-1234” } ).

      To determine which one to use, test if the record exists and then which syntax to employ, you can use an If() function combined with an IsBlank().  Something like:

    If(IsBlank(Lookup(Customers,Name="Contoso"),Patch( Customers, Defaults( Customer ), { Name: “Contoso” } ),Patch( Customers, Lookup( Customers, Name = "Contoso" ) , { Phone: “1-212-555-1234” } ))

      

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 329 Most Valuable Professional

#2
11manish Profile Picture

11manish 209 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 179

Last 30 days Overall leaderboard