#039 BC TITLE AND CUSTOM ACTIONS ON ERROR DIALOGS
With the release of Business Central 2023 Wave 1 some features have been enhanced. In this ArquiTips we will explore the possibility of adding Title and Custom Actions to Error Dialogs making messages more user-friendly.
It’s possible to add up to two custom actions, that will be displayed on the Error dialog, to provide users with corrective actions, by using the ErrorInfo Object.
This can be achieved by calling the AddAction method on the ErrorInfo Object, which can be passed to AL methods that support ErrorInfo, such as Error, Testfield, FieldError, etc.
As an example, we can have the following type of errors:
As we can see above, we have two different actions on our error, that will show us different messages if we click on them.
Error Action 1:
Error Action 2:
To achieve this outcome, we need to create the following code:
The AddAction method receives three parameters:
- Caption: The text string that appears as the caption of the action in the error UI.
- CodeunitID: The ID of the Codeunit to run. This Codeunit should contain at least one global method to be called by the error action. The global method must have an ErrorInfo data type parameter for accepting the ErrorInfo Object.
- Method Name: The name of the method in the Codeunit specified before.
With Business Central 2023 Wave 1 (BC22), a new navigation action for the errors has been added.
That being sad, if we for instance, want the user to navigate to the item list when the error occurs, we can add an action to the error for this purpose and the user will go directly from the error message to the item list, in one click.
And the sample code to do it:
There is also a new behavior about Error Messages that is important to mention.
In the previous version of Business Central, the action error message had a dropdown How to Report this issue button.
When we clicked on this button, we could see some information, and we had another button – Copy information to clipboard – and if we copied it, we could paste it elsewhere, for instance on a notepad, and see exactly where our program stopped.
Now, with the release of the new BC22, this has changed a little, and we have right on the error message a button Copy Details that does the same thing as the Copy information to clipboard.
When we copy the information, we get this message confirming it, and we just need to paste it where is convenient for us, for example notepad.