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 / Comparing Patch Statem...
Power Apps
Unanswered

Comparing Patch Statements

(0) ShareShare
ReportReport
Posted on by 1,401 Moderator

I just want to verify these are the same before making changes. I'm editing an app made by a previous employee.

 

Is this...

Patch(
 Inventory,
 {ID:CreateBundleForm.LastSubmit.ID},
 {IDRef: CreateBundleForm.LastSubmit.ID}
);
Patch(
 Inventory,
 {ID:CreateBundleForm.LastSubmit.ID},
 {'Invoice Number':"False"}
);

 

The same as this:

Patch(
 Inventory,
 {
 ID: CreateBundleForm.LastSubmit.ID,
 IDRef: CreateBundleForm.LastSubmit.ID,
 'Invoice Number': "False"
 }
);

 

Or is there something I'm missing as to why this would be separated into two Patch statements.

Categories:
  • BCBuizer Profile Picture
    22,899 Super User 2026 Season 2 on at

    Hi @IPC_ahaas ,

     

    Indeed there is not need to use two Patch functions for this, but you do have to take the syntaxis for the function into account:

     

    Patch( DataSource, BaseRecord, ChangeRecord1 [, ChangeRecord2, … ])

     

    So the way to combine them:

     

    Patch(
     Inventory,
     {
     ID: CreateBundleForm.LastSubmit.ID
     },
     {
     IDRef: CreateBundleForm.LastSubmit.ID,
     'Invoice Number': "False"
     }
    );
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @IPC_ahaas 

    No, they are not identical.

    Your first one is performing 2 data operations, whereas your second is only performing 1.

    The second one is the way to go.

     

    I hope this is helpful for you.

  • IPC_ahaas Profile Picture
    1,401 Moderator on at

    Is the reason for the separate statements because this is updating an existing item?

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @IPC_ahaas 

    There is no need to separate the parameters.

    Patch is smart enough to know what to do based on your inclusion of the ID.

     

     

  • IPC_ahaas Profile Picture
    1,401 Moderator on at

    Let me rephrase:

     

    I don't know what "LastSubmit" does. This is in the OnSuccess of a Form. I had assumed the Patch statement would be much larger considering there are at least 10 fields. Instead, it has this short Patch.

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @IPC_ahaas 

     

    You're introducing LastSubmit into this now...

    I will first say, you should NOT be patching anything in your record you just submitted...it should be all done in your form!

     

    LastSubmit represents the last record that was submitted.

     

    What is it exactly that you are looking at and trying to do?

  • IPC_ahaas Profile Picture
    1,401 Moderator on at

    I didn't build it! I was just called in to fix it. The app is full of items not named so I've spent the last two days trying to figure out how this app works.

     

    This app has a Submit button with OnSelect:

    SubmitForm(CreateBundleForm);

     

    The "CreateBundleForm" has OnSuccess (with changes made from this thread)

    Patch(
     Inventory,
     {
     ID: CreateBundleForm.LastSubmit.ID,
     IDRef: CreateBundleForm.LastSubmit.ID,
     'Invoice Number': "False"
     }
    );
    
    NewForm(CreateBundleForm);
    
    Set(var1,Blank());
    Set(var2,Blank());
    Set(var3,Blank());
    Set(var4,Blank());
    Set(var5,Blank());
    Set(var6,Blank());
    Set(var7,Blank());
    Set(var8,Blank());
    
    Select(ResetButton);

     

    and "ResetButton" has OnSelect:

    NewForm(CreateBundleForm);
    
    Set(var1,Blank());
    Set(var2,Blank());
    Set(var3,Blank());
    Set(var4,Blank());
    Set(var5,Blank());
    Set(var6,Blank());
    Set(var7,Blank());
    Set(var8,Blank());
    
    Select(BtnConfirmError);

     

    And "BtnConfirmError" has OnSelect:

    UpdateContext({Alert:false});
    Set(serial1,Blank());
    Reset(BarcodeScanner)

     

    To me, this looks like it does the same thing multiple times and only submits two pieces of data into an existing ID. There are objects that seem like they'll display if an existing tries to be submitted, but I can't tell how they execute yet.

     

    There are a lot of areas this app is working harder than it needs to, and I'm trying to simplify it. It has some code I haven't come across before, such as "LastSubmit".

  • IPC_ahaas Profile Picture
    1,401 Moderator on at

    The more I think about it, the more this Patch code seems nonsensical. It's updating the most recent by setting the "IDRef" column to its current "ID" value?

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @IPC_ahaas 

    Yeah, there is a lot of redundancy in those formulas, plus a lot of variable usage (which should always be minimized).

     

    The only value to setting the IDRef like that is in the event that you are doing some sort of filtering on the ID that is not delegable but would be on a regular numeric column.

  • IPC_ahaas Profile Picture
    1,401 Moderator on at

    I tested it, and it does in fact submit a whole bunch of other data into the List. I clearly need an education on how Forms work.

     

    On the Form, it has a bunch of "Fields" which are actually "Datacards". How does it know what field within the "Datacard" to submit into the List?

     

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 342 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 271

#3
Mohsin Ali Profile Picture

Mohsin Ali 223

Last 30 days Overall leaderboard