Good error handling is the best way to ensure users can get through the different errors that may appear while working with Business Central. In this article, you will learn what are actionable errors and how to use them to improve the user experience.

  • What Are Actionable Errors
  • How To Use Inline Actionable Errors
  • How To Use Dialog Actionable Errors
  • How To Use Show-It Actions

What Are Actionable Errors


Actionable errors are a way to facilitate error handling for users in Business Central. When users get an error, they often don’t understand it or know how to solve it. With actionable errors, we can help them in this task.

There are two types:

  • Inline Validation Errors
  • Dialog Errors

How To Use Inline Actionable Errors


Inline actionable errors are used when a field validation happens and an error is raised. This feature was introduced in BC23.

For example, in this video, you can see a standard inline error where we try to input more quantity than is possible. In this case, we can fix the error directly in the dialog by either refreshing or by selecting the fix-it action “Set value to 3”.

Let’s now create a custom inline actionable error.

In our custom example, an error will be raised to add the mobile phone prefix to the customer card. Depending on the country region code.

As you can see, an action to immediately fix it appears:

First, extend the customer table and add the call to our functions in the “OnAfterValidate” trigger of the “Mobile Phone No.” field.

The key is the “ErrorInfo” data type. As you can see, with it, you can build the title of the error message, the message itself, and add the action to take. Finally, you end with “Error(

This is an example to illustrate the concept better. As you can see, values are hardcoded and do not represent a valid customization in real life. What’s important is the idea behind it.

The action will trigger the method that applies the logic. The only requirement is that it must have “ErrorInfo” as a parameter. With ErrorInfo data type you can get the record with “ErrorInfo.RecordId” and modify it with the new value.

The “SetMobilePhoneNo” procedure is just a way to assign the value that the user has input.

A valid solution would look something like this:

codeunit 50029 ActionableErrorsBCG
{
    SingleInstance = true;

    var
        MobilePhoneNoInput: Text[30];
        Extension: Text[5];

    procedure InlineValidationCustMobilePhoneError(Customer: Record Customer)
    var
        ActionTitleLbl: Label 'Add %1 prefix';
        MessageErrLbl: Label '%1 Customers must be prefixed with %2';
        ErrorTitleLbl: Label 'Phone No. is not valid';
        ErrorActionMethodLbl: Label 'InlineValidateErrorMethod', Locked = true;
        MobilePhoneErrorInfo: ErrorInfo;
    begin
        if HasExtensionMobilePhoneInput(Customer, MobilePhoneNoInput) then
            exit;

        Extension := GetCountryExtensionCode(Customer."Country/Region Code");
        MobilePhoneErrorInfo.Title(ErrorTitleLbl);
        MobilePhoneErrorInfo.Message(StrSubstNo(MessageErrLbl, Customer."Country/Region Code", Extension));
        MobilePhoneErrorInfo.RecordId(Customer.RecordId);
        MobilePhoneErrorInfo.AddAction(StrSubstNo(ActionTitleLbl, Extension), Codeunit::ActionableErrorsBCG, ErrorActionMethodLbl);
        Error(MobilePhoneErrorInfo);
    end;

    procedure InlineValidateErrorMethod(ErrorInfo: ErrorInfo)
    var
        Customer: Record Customer;
    begin
        Customer.Get(ErrorInfo.RecordId);
        Customer."Mobile Phone No." := Extension + ' ' + MobilePhoneNoInput;
        Customer.Modify(true);
    end;

    internal procedure SetMobilePhoneNo(MobilePhoneNo: Text[30])
    begin
        MobilePhoneNoInput := MobilePhoneNo;
    end;

    local procedure GetCountryExtensionCode(CountryRegionCode: Code[10]): text
    begin
        // Search for extension based on country
        exit('+1');
    end;

    local procedure HasExtensionMobilePhoneInput(Customer: Record Customer; MobilePhoneNoInput: Text[30]): Boolean
    begin
        // Check if the phone no. already has the correct extension
        exit(false);
    end;
}


How To Use Dialog Actionable Errors


Message errors are very similar to inline validation errors. The only difference is that they don’t occur when validating fields. They are shown in processes like this one.

We can use the same codeunit built above but instead of calling from an OnValidate trigger we can call it from an action.

And the result is a pop-up window with the option to fix the phone No.

How To Use Show-It Actions


There is also the possibility since BC23 to navigate to a specific table from the error. If we know where users should fix the error we can give them the possibility to navigate to it straight away.

With the following result

If you want to learn more about handling errors follow the article below:

You can find more information about actionable errors in Microsoft’s documentation:

Actionable errors – Business Central | Microsoft Learn


That´s all. Hope you find it helpful.

How To Improve Error Handling With Actionable Errors In Business Central

Post navigation


Leave a Reply

Your email address will not be published. Required fields are marked *