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 Working Until I ...
Power Apps
Answered

Patch Working Until I Add A Variable for Error Handling

(0) ShareShare
ReportReport
Posted on by 134

Here is my patch code that works.

// Patch works as expected
If(
 First(colJobInfoCupMachine).JobStatus = "Ready for Review",
 Patch('DS Pre Op Insp Jobs', LookUp('DS Pre Op Insp Jobs', ID = argHomeParentID), {
 'Tech Approval Comments': txtModalApproveComments.Text,
 'Tech Approval DateTime': Now(),
 JobStatus: {Value: "Tech Approved"}
 }),
 First(colJobInfoCupMachine).JobStatus = "Tech Approved",
 Patch('DS Pre Op Insp Jobs', LookUp('DS Pre Op Insp Jobs', ID = argHomeParentID), {
 'Prod Mgr Name': User().FullName,
 'Prod Mgr Approval Comments': txtModalApproveComments.Text,
 'Prod Mgr Approval DateTime': Now(),
 JobStatus: {Value: "Prod Super Approved"}
 }),
 First(colJobInfoCupMachine).JobStatus = "Prod Super Approved",
 Patch('DS Pre Op Insp Jobs', LookUp('DS Pre Op Insp Jobs', ID = argHomeParentID), {
 'QA Supervisor Name': User().FullName,
 'QA Super Approval Comments': txtModalApproveComments.Text,
 'QA Supervisor Approval Date Time': Now(),
 'Inspection Date Completed': Now(),
 JobStatus: {Value: "Approved"}
 })
);

And here is the code where I add error handling and it no longer works.

// Patch Not Successful - Errors
If(
 First(colJobInfoCupMachine).JobStatus = "Ready for Review",
 Set(varPatchResult, Patch('DS Pre Op Insp Jobs', LookUp('DS Pre Op Insp Jobs', ID = argHomeParentID), {
 'Tech Approval Comments': txtModalApproveComments.Text,
 'Tech Approval DateTime': Now(),
 JobStatus: {Value: "Tech Approved"}
 })),
 First(colJobInfoCupMachine).JobStatus = "Tech Approved",
 Set(varPatchResult, Patch('DS Pre Op Insp Jobs', LookUp('DS Pre Op Insp Jobs', ID = argHomeParentID), {
 'Prod Mgr Name': User().FullName,
 'Prod Mgr Approval Comments': txtModalApproveComments.Text,
 'Prod Mgr Approval DateTime': Now(),
 JobStatus: {Value: "Prod Super Approved"}
 })),
 First(colJobInfoCupMachine).JobStatus = "Prod Super Approved",
 Set(varPatchResult, Patch('DS Pre Op Insp Jobs', LookUp('DS Pre Op Insp Jobs', ID = argHomeParentID), {
 'QA Supervisor Name': User().FullName,
 'QA Super Approval Comments': txtModalApproveComments.Text,
 'QA Supervisor Approval Date Time': Now(),
 'Inspection Date Completed': Now(),
 JobStatus: {Value: "Approved"}
 }))
);

// Check for Patch errors
If(IsBlank(varPatchResult), 
 // There are no errors
)

Any recommendations are appreciated. 

Categories:
I have the same question (0)
  • EddieE Profile Picture
    4,641 Moderator on at

    @zoso2112 

    Define "... no longer working ...". If you mean this code is on a button and button click does nothing then your last If() is the issue - you need to finish it, ie

    // Check for Patch errors
    If(IsBlank(varPatchResult), 
     // ... do some action here ... <-- add your code here
    
     // There are no errors
    )

     

     

  • zoso2112 Profile Picture
    134 on at

    @EddieE - Thank you for your response. Once I added the variable varPatchResult to the Patch code,

    Set(varPatchResult,

    the Patch() function failed to save the data.
    The code below explains what actions to take depending if the Patch failed.

    // Check for Patch errors
    If(IsBlank(varPatchResult), 
     // There are no errors - Notify user and close modal window
    
     // ELSE - There was an error so notify user, email sys admins, and close modal window
    )

     I have also tried 

    // Check for Patch errors
    If(!IsBlank(Errors('DS Pre Op Insp Jobs', varPatchResult)),
     // There are no errors - Notify user and close modal window
    
     // ELSE - There was an error so notify user, email sys admins, and close modal window
    )

    but the Patch() function failed to save the data with this alt code. In my app's settings I have the "Formula-Level Error Management" option enabled.  

  • Verified answer
    zoso2112 Profile Picture
    134 on at

    @EddieE - I figured it out. i just needed to add this code and it is now working. 

    // Check for errors
    Set(varErrors, Errors('DS Pre Op Insp Jobs', varPatchResult));
    // Count the number of errors
    Set(varErrorCount, CountRows(varErrors));
    
    // If there are errors, display the first one
    If(!IsEmpty(varErrors), 
     // Patch error occurred
    )

    Thanks for your response. 

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 321 Super User 2026 Season 1

#2
WarrenBelz Profile Picture

WarrenBelz 289 Most Valuable Professional

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 200 Super User 2026 Season 1

Last 30 days Overall leaderboard