cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Kudo Kingpin
Kudo Kingpin

Save error messages

I am trying to collect error messages and save them to a CDS entity so that we can track which users are getting what errors. I've written this code (it's in OnFailure) which DOES save a record to the entity, but the four fields that are supposedly available through the Errors() function just show up with nothing.

 

 

Patch(EST_Errors, Defaults(EST_Errors),
    {
    Errors_Column: First(Errors(EST_Project_Estimates)).Column,
    Errors_Kind: First(Errors(EST_Project_Estimates)).Error,
    Errors_Message: First(Errors(EST_Project_Estimates)).Message,
    Errors_Record: First(Errors(EST_Project_Estimates)).Record.Estimate_Name,
    Errors_Screen: "Estimate Edit"
    }
)

The only one of these 5 fields that has anything in it is the one where I just save the typed string. The fields are all multiline text. There are no errors when running this code. Is there a better way to do this?

 

5 REPLIES 5
Highlighted
Power Apps
Power Apps

Re: Save error messages

@Boneckrh19 ,

It sounds like you want to write the errors your users are receiving to a CDS entity using the data from the Errors() function.

 

Since the Errors function returns a table worth of errors, you could use ForAll() to repeat the patch for each potential error.

 

ForAll(Errors(table_name),
    Patch(EST_Errors, Defaults(EST_Errors),
        {
            Errors_Column: Column,
            Errors_Kind: Error,
            Errors_Message: Message,
            Errors_Record: Name,
            Errors_Screen: "Estimate Edit"
        }
    )
)

The benefit is that the ForAll will write the respective column, error, message, so you do not need to use the First() function. This also lets you scale out the statement to capture multiple errors.

Highlighted
Kudo Kingpin
Kudo Kingpin

Re: Save error messages

Unfortunately the code you provided does not patch any records to my errors entity at all. The code I had did patch an error record on failure, it's just that those four fields were always empty. 

(As a side note, I don't actually need it to save every error on every save attempt, since that will cause some redundancy.)

Highlighted
Community Support
Community Support

Re: Save error messages

Hi @Boneckrh19 ,

Do you submit your form data using SubmitForm() function?

Based on the issue that you mentioned, I have made a test on my side, and don't have the issue that you mentioned.

The screenshot as below:4.JPG

 

5.JPG

There are also some known limits with Errors() function. E.G. The Record property within the result the Errors() function returns would be blank when the error occurred during the creation of a record.

Please check the following article for more details:

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

 

I also have made a test on my side (using SubmitForm function to submit form data), and found that the Errors() function could not capture the error message within the Edit form submitted using SubmitForm() function.

As an fixed solution, please consider take a try to submit your form data into your data source (EST_Project_Estimates) using Patch function instead of SubmitForm() function. Please take a try with the following workaorund:

Set the OnSelect property of the "Submit" button to following:

Patch(
          EST_Project_Estimates,
          Defaults(EST_Project_Estimates),
          EditForm1.Updates               /* <-- EditFrom1 represents the Edit form control in your app */
);
If(
   IsEmplty(Errors(EST_Project_Estimates)),
   Back()
)

Set the OnFailure property of the Edit form (EditForm1) to following:

Patch(
EST_Errors,
Defaults(EST_Errors), { Errors_Column: First(Errors(EST_Project_Estimates)).Column, Errors_Kind: First(Errors(EST_Project_Estimates)).Error, Errors_Message: First(Errors(EST_Project_Estimates)).Message, Errors_Record: First(Errors(EST_Project_Estimates)).Record.Estimate_Name, Errors_Screen: "Estimate Edit" } )

Please take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Anonymous
Not applicable

Re: Save error messages

Thanks for posting in the community @Boneckrh19. Are you still experiencing this issue? Can you review the above reply and update the thread if it was helpful?

 

Thank you,

 

@Anonymous 

Highlighted
Kudo Kingpin
Kudo Kingpin

Re: Save error messages

This solution patched one record with a message back to my entity the first time I tried it, but then won't patch anything after that. It's not being overridden either, since the modified datetime and the created datetime are the same. Not really sure what happened there.

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,207)