Dynamics 365 Business Central 2023 Wave 1 – Provide Title and custom actions to Error dialogs

With each update of Dynamics 365 Business Central, Microsoft enhances what is often referred to as the base application and enhances the development environment. Dynamics 365 Business Central 2023 Wave 1 has several exciting Development features for runtime 11.0. One of the exciting features is to Provide Title and custom actions to Error dialogs.

To assist users in better dealing with errors encountered while using Microsoft Dynamics 365 Business Central, a new feature was added that enables developers to allow users to select an appropriate corrective action when an error occurs. Improving the clarity of error messages is essential in instilling confidence in Business Central while streamlining the process of correcting common problems.

Now, developers can enhance issue descriptions by setting the Title property on Error dialogs presented to the user. Moreover, by utilizing the ErrorInfo object, developers can include up to three customized actions on the Error dialog to provide corrective measures to the user. This can be accomplished by invoking the AddAction method on the ErrorInfo object, which can be transmitted to AL methods that support ErrorInfo, including Error, TestField, FieldError, and other methods. The ErrorInfo object also has a number of properties that enhance the Telemetry information.

codeunit 50100 "DVLPR Error Management"
{
    var
        ErrorActionMsg: Label 'Action %1 for %2.\Let''s handle it', Comment = '%1 Action Number %2 Action Message';

    procedure ErrorAction1(ErrorInfo: ErrorInfo)

    begin
        Message(ErrorActionMsg, '1', ErrorInfo.Title);
    end;

    procedure ErrorAction2(ErrorInfo: ErrorInfo)
    begin
        Message(ErrorActionMsg, '2', ErrorInfo.Title);
    end;
}
pageextension 50100 "DVLPR Customer List Ext" extends "Customer List"
{
    actions
    {
        addlast("&Customer")
        {
            action(DVLPRError)
            {
                ApplicationArea = Basic, Suite;
                Caption = 'Error Demo';
                Image = Error;
                ToolTip = 'Demonstration Error Add Action';

                trigger OnAction()
                var
                    ErrorInfo: ErrorInfo;
                begin
                    ErrorInfo.Title := 'DVLPR Error Demonstration';
                    ErrorInfo.ErrorType := ErrorType::Client;
                    ErrorInfo.Verbosity := Verbosity::Error;
                    ErrorInfo.DataClassification := DataClassification::CustomerContent;
                    ErrorInfo.Message := 'This is a error! What would you like to do?';
                    ErrorInfo.AddAction('Action 1', Codeunit::"DVLPR Error Management", 'ErrorAction1');
                    ErrorInfo.AddAction('Action 2', Codeunit::"DVLPR Error Management", 'ErrorAction2');

                    Error(ErrorInfo);
                end;
            }
        }
    }
}

The AddAction method accepts 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 when the action is initiated from the error UI. The 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, which is specified by the CodeunitID parameter, that you want to run for the action.

Read more about the feature Provide Title and custom actions to Error dialogs here.

Note: The code and information discussed in this article is for informational and demonstration purposes only. This content was created referencing Microsoft Dynamics 365 Business Central 2023 Wave 1 online.

Leave a Reply

Your email address will not be published.