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 / How do I use the 'Erro...
Power Apps
Answered

How do I use the 'Errors' function correctly?

(0) ShareShare
ReportReport
Posted on by 241

This is kind of related to my previous post but I think it warrants its own thread as it's a separate issue.

 

I tried to do a patch using the following code:

 

 

 UpdateContext({ guid: First(savebufferProjects).PrjId });
 UpdateContext({ patchresultProject: Patch( Projects, LookUp( Projects, Project=guid),{
 Planningstatus: 'Planningstatus (Projects)'.Geaudit 
 })});
 If( IsEmpty( Errors( Projects, patchresultProject ) ),
 RemoveIf( savebufferProjects, PrjId=guid );
 RemoveIf( schFlush_buffer, id=guid );
 SaveData( savebufferProjects, "savebufferProjects" );
 // trigger continue
 UpdateContext({ sendaction: true });
 , 
 Notify("Error:"&First(Errors(Projects, patchresultProject)).Message );
 );

 

 

Note that I check the patch result using the Errors function.

 

In my situation, the patch failed due to insufficient permissions. If this were the case, I would have expected this information to be contained in the patch result, and my own code should have shown a notification. However, that never happened; instead, the other branch in the IF statement was executed (removing the item from the buffer and continuing with other code).

 

What am I doing wrong here?

Categories:
I have the same question (0)
  • Verified answer
    v-bofeng-msft Profile Picture
    Microsoft Employee on at

    HI @ MrNappa:

    Could you tell me have you checked your data source? Whether the patch function has run successfully?

    Taking into account the problem you mentioned ,my suggestion is: Do not use the return value of the patch directly.

    Firstly, let me explain why you are not recommended to do this:

    Errors can be returned for the entire data source, or for only a selected row by providing the Record argument to the function.

    patch or another data function may return a blank value if, for example, a record couldn't be created. You can pass blank to Errors, and it will return appropriate error information in these cases. Subsequent use of data functions on the same data source will clear this error information. I think this link will help you a lot.

    Errors function in Power Apps:

    https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-errors

    Secondly ,I suggest you try this code:

     UpdateContext({ guid: First(savebufferProjects).PrjId });
     UpdateContext({ patchresultProject: LookUp( Projects, Project=guid));
     Patch(Projects, patchresultProject, {Planningstatus: 'Planningstatus (Projects)'.Geaudit});
     If( IsEmpty( Errors( Projects, patchresultProject ) ),
     RemoveIf( savebufferProjects, PrjId=guid );
     RemoveIf( schFlush_buffer, id=guid );
     SaveData( savebufferProjects, "savebufferProjects" );
     // trigger continue
     UpdateContext({ sendaction: true });
     ,
     Notify("Error:"&First(Errors(Projects, patchresultProject)).Message );
     );

    Best Regards,

    Bof

  • MrNappa Profile Picture
    241 on at

    Thanks -- it wasn't really apparent to me that I needed to pass the original record to the Errors function. Especially because the return value of Patch is also a record.

     

    Tried your suggestion and it worked!

  • MrNappa Profile Picture
    241 on at

    Hi @v-bofeng-msft 

     

    I have a follow up question. I also tried some error handling on creating a new record, but... I get an unexpected error.

     

    Consider the code from this screenshot:

    errorscheck.jpg

    Here I'm testing 2 patches to create records. The code is the equivalent (the lookup in the first patch doesn't make a difference), except they operate on different data sources (both are CDS data sources).

     

    However, as you can see, using the errors function on the first table works fine, but it fails on the second table.

     

    Do you have any ideas what's the cause of this? 

  • v-bofeng-msft Profile Picture
    Microsoft Employee on at

    Hi @MrNappa :

    I suggest you try this code:

    Errors(Registraties)

    Best Regards,

    Bof 

  • MrNappa Profile Picture
    241 on at

    Thanks, using the Errors function without parameter as you suggested works.... but why is there a difference in the first place?

  • v-bofeng-msft Profile Picture
    Microsoft Employee on at

    Hi @MrNappa ï¼š

    If you don't specify this argument(Record ), the function returns errors for the entire data source.

    Best Regards,

    Bof

  • MrNappa Profile Picture
    241 on at

    I know, that's in the docs. I'm just wondering why Errors( Projectdefinities, newProjectdefinitie ) is valid, while Errors( Registratie, newRegistratie ) is not.

  • v-bofeng-msft Profile Picture
    Microsoft Employee on at

    Hi @MrNappa :

    Your current operation is to create a record. If you created a record, the return value may include properties that the data source generated automatically. However, the return value doesn't provide a value for fields of a related entity.

    I think this link will help you a lot:

    Patch function in Power Apps:

    https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-patch#description

    Best Regards,

    Bof

  • MrNappa Profile Picture
    241 on at

    I was investigating a bit further because it bothered me. I think I found the underlying cause: PowerApps gives this error when Notes have been enabled for the entity.

     

    It's very easy to see. I created a test entity and then used this code:

    UpdateContext({
     newTestEntity: Patch( TestEntities, Defaults(TestEntities), { new_name: "test" } )
    });
    If( IsEmpty( Errors( TestEntities, newTestEntity ) )
     , Notify("success!");
     , Notify("failed:"&First(Errors(TestEntities, newTestEntity)).Message );
    );

    This worked fine, as expected. But as soon as I modified the entity to enable notes, and refreshed the data source in PowerApps, it started giving me the error again. 

     

    Not sure if that's a bug or a feature.

  • MarceloBarroso Profile Picture
    39 on at

    hI @MrNappa ,

     

    after a lot of trouble around this issue, and some time recreating the entity since it's not allowed to uncheck the "notes" feature after it is checked, the Errors() function is now working.

    Thank you for your digging.

     

    Best wishes.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 541

#2
WarrenBelz Profile Picture

WarrenBelz 434 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 289

Last 30 days Overall leaderboard