Business Central 2023 wave 1 (BC22) new features: Provide Title and custom actions to Error dialogs (Custom Actions in error messages)

Dynamics 365 Business Central

Hi, Readers.
The public preview for Dynamics 365 Business Central 2023 release wave 1 (BC22) is available. Learn more: Link.

I will continue to test and share some new features that I hope will be helpful.

Provide Title and custom actions to Error dialogs:

Business value:
To help users get unblocked from issues when working with Business Central, we’ve introduced the capability to allow developers to unblock users when they encounter issues right away by choosing a corrective action. Making error messages more user-friendly helps build trust in Business Central while at the same time saving time in correcting common issues.

https://learn.microsoft.com/en-us/dynamics365/release-plan/2023wave1/smb/dynamics365-business-central/provide-title-custom-actions-error-dialogs

Developers can now set the Title property on Error dialogs that are presented to the user to enrich issue description. On top of that, using the ErrorInfo object, developers can add up to three custom actions that will be displayed on the Error dialog to provide users with corrective actions. 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, and others.

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.

First of all, what is ErrorInfo object? This is new feature in 2021 release wave 2 plan, Collectable errors in AL.

Allow AL developers to write AL code that returns more than one error. The feature can be used to simplify validation scenarios where users can be presented with a list of things to fix.

ErrorInfo Data Type: Provides a structure for grouping information about an error.

More details from MS:

With this wave, two new methods have been added.
VersionAvailable or changed with runtime version 11.0.

ErrorInfo.Title([Text]) Method: Specifies the title of the error.

Syntax: [Title := ] ErrorInfo.Title([Title: Text])

Parameters:

ErrorInfo
 Type: ErrorInfo
An instance of the ErrorInfo data type.

[Optional] Title
 Type: Text
The title of the ErrorInfo

Return Value:

[Optional] Title
 Type: Text
The current title of the ErrorInfo.

ErrorInfo.AddAction(Text, Integer, Text) Method: Specifies an action for the error.

Syntax: ErrorInfo.AddAction(Caption: Text, CodeunitID: Integer, MethodName: Text)

Parameters:

ErrorInfo
 Type: ErrorInfo
An instance of the ErrorInfo data type.

Caption
 Type: Text

The text string that appears as the caption of the action in the error UI. The string can be a text constant that is enabled for multilanguage functionality.

CodeunitID
 Type: Integer

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.

MethodName
 Type: Text
The name of the method in the Codeunit, which is specified by the CodeunitID parameter, that you want to run for the action.

PS: Please note that if there is not at least one global method in your Codeunit, or there is no ErrorInfo data type parameter in the global method, it will cause a runtime error.

Let’s take a look at the full test.

It looks very good.😁

Click Error Action 1:

Click Error Action 2:

Source Code:


pageextension 50100 CustomerListExt extends "Customer List"
{
    actions
    {
        addfirst(processing)
        {
            action(RunErrorAction)
            {
                Caption = 'Run Error Action';
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                PromotedOnly = true;
                ApplicationArea = All;
                Image = ExecuteBatch;

                trigger OnAction()
                begin
                    TestErrorAction();
                end;
            }
        }
    }

    local procedure TestErrorAction()
    var
        ZYErrorInfo: ErrorInfo;
    begin
        ZYErrorInfo.DataClassification(DataClassification::SystemMetadata);
        ZYErrorInfo.ErrorType(ErrorType::Client);
        ZYErrorInfo.Verbosity(Verbosity::Error);
        ZYErrorInfo.Title('This is New Error Title!!!');
        ZYErrorInfo.Message := 'This is Error Message';
        ZYErrorInfo.AddAction('Error Action 1', Codeunit::"Error Action Test", 'Test01');
        ZYErrorInfo.AddAction('Error Action 2', Codeunit::"Error Action Test", 'Test02');
        Error(ZYErrorInfo);
    end;
}

codeunit 50111 "Error Action Test"
{
    procedure Test01(ZYErrorInfo: ErrorInfo)
    begin
        Message('Test 01');
    end;

    procedure Test02(ZYErrorInfo: ErrorInfo)
    begin
        Message('Test 02');
    end;
}

Give it a try!!!😁

Updated: Business Central 2023 wave 1 (BC22) new features: Get unblocked using actionable error messages in select application areas

Update 2023.03.31:
ErrorInfo.AddNavigationAction() Method: Adds a navigation action for the error.

Test Video:

Source Code:

pageextension 50100 CustomerListExt extends "Customer List"
{
    actions
    {
        addfirst(processing)
        {
            action(RunErrorAction)
            {
                Caption = 'Run Error Action';
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                PromotedOnly = true;
                ApplicationArea = All;
                Image = ExecuteBatch;
                trigger OnAction()
                begin
                    TestErrorAction();
                end;
            }
        }
    }
    local procedure TestErrorAction()
    var
        ZYErrorInfo: ErrorInfo;
    begin
        ZYErrorInfo.DataClassification(DataClassification::SystemMetadata);
        ZYErrorInfo.ErrorType(ErrorType::Client);
        ZYErrorInfo.Verbosity(Verbosity::Error);
        ZYErrorInfo.Title('This is New Error Title!!!');
        ZYErrorInfo.Message := 'This is Error Message';
        ZYErrorInfo.AddAction('Error Action 1', Codeunit::"Error Action Test", 'Test01');
        ZYErrorInfo.PageNo := Page::"Item List";
        ZYErrorInfo.AddNavigationAction('Open Item List');
        Error(ZYErrorInfo);
    end;
}
codeunit 50111 "Error Action Test"
{
    procedure Test01(ZYErrorInfo: ErrorInfo)
    begin
        Message('Test 01');
    end;
}

PS:
1. Please do not use the ErrorInfo.Create() Method, which will cause the Action Title not to be displayed. But the actions can be displayed normally.

2. Although the number of actions that can be added is not stated in MS Learn (Docs), according to my test, if adding 3 buttons, a runtime error will also occur. So it looks like the maximum support is two actions.

Business Central Launch Event (2023 release wave 1) 

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL