NavigationAction for ErrorInfo data type

by Mar 2, 2023AL Language

Home 9 Development 9 AL Language 9 NavigationAction for ErrorInfo data type

One more article about ErrorInfo data type. Have you already read my previous posts about ErrorInfo and Collectible Errors?

Navigation Action for Errors

You already know the custom actions for error messages from my previous post. However, the upcoming release (Microsoft Dynamics 365 Business Central 2023 wave 1 contains one more interesting enhancement for error dialogue gues – navigation actions).

These actions allow you to open a specific page & a record directly from the error message. The same could also be done using the custom action, but it would require much more effort as you would need to create a whole new procedure. With the navigation action, you are able to specify which page and which record should be open using this action.

Note: In the upcoming version 2023 wave 1, navigation actions & custom error actions will be available for the Error method only! Microsoft plans to add support for this functionality also for TestFields methods (with the error dialogue & inline error dialogue) in future releases.

The navigation action could be added to any ErrorInfo object using the method ErrorInfo.AddNavigationAction() Method – Business Central | Microsoft Learn. But how to specify which page/record should be opened? For this purpose, there are methods that had existed already since BCv19 when the ErrorInfo data type was introduced – ErrorInfo.PageNo([Integer]) Method – Business Central | Microsoft Learn and ErrorInfo.RecordId([RecordId]) Method – Business Central | Microsoft Learn. Furthermore, you can preset the focus to a specific field on the page using ErrorInfo.FieldNo([Integer]) Method – Business Central | Microsoft Learn (for example, if the problem is the customer posting group, you can preset the focus to this field)

Let’s look at some examples.

procedure DoSomething(Customer: Record Customer)
var
    MyErrorInfo: ErrorInfo;
begin
    MyErrorInfo.Title := 'Ouu noo!';
    MyErrorInfo.Message := StrSubstNo('Something terrible has happened with customer %1, %2.', Customer."No.", Customer.Name);

    MyErrorInfo.PageNo(Page::"Customer Card");
    MyErrorInfo.FieldNo(Customer.FieldNo("Customer Posting Group"));
    MyErrorInfo.RecordId(Customer.RecordId());
    MyErrorInfo.AddNavigationAction();
    Error(MyErrorInfo);
end;

So what happens when this code is executed? The error message is shown with a custom title & text and two buttons – standard OK that just close the dialogue and the new “Navigate” action.

When we choose the “Navigate” action, the customer card for customer 50000 is opened.

If we want to open a page and we do not care about the specific record (yeah, it makes sense for the setup tables, for example, the “Sales & Receivables Setup”), we do not need to initialize the record variable. We just need to set the page we want to open. See the example below.

procedure DoSomething(Customer: Record Customer)
var
    MyErrorInfo: ErrorInfo;
begin
    MyErrorInfo.Title := 'Ouu noo!';
    MyErrorInfo.Message := StrSubstNo('There is something wrong with the sales setup as the customer %1, %2 could not be used.', Customer."No.", Customer.Name);

    MyErrorInfo.PageNo(Page::"Sales & Receivables Setup");
    MyErrorInfo.AddNavigationAction();
    Error(MyErrorInfo);
end;

We can even combine NavigationAction with our custom actions (see the previous article about how to create & use custom actions).


procedure DoSomething(Customer: Record Customer)
var
    MyErrorInfo: ErrorInfo;
begin
    MyErrorInfo.Title := 'Ouu noo!';
    MyErrorInfo.Message := StrSubstNo('There is something wrong with the sales setup as the customer %1, %2 could not be used.', Customer."No.", Customer.Name);

    MyErrorInfo.PageNo(Page::"Sales & Receivables Setup");
    MyErrorInfo.AddNavigationAction();
    MyErrorInfo.AddAction('Why?!', Codeunit::"TKA Resolve It", 'TrySolve2');
    Error(MyErrorInfo);
end;

Recent Articles from the category

Error actions for ErrorInfo data type

Error actions for ErrorInfo data type

It is already almost one and a half years since the ErrorInfo data type was introduced (we saw this data type for the first time in BC2021w2). If you do not know what it is and how to use this data type, check my previous posts: ErrorInfo data type & Collectible...

read more
Data types under the microscope: List

Data types under the microscope: List

The List data type in AL language represents an ordered collection of objects that can be accessed by their index. Unlike an Array data type, a List does not have a fixed size and does not need to have its dimension specified when it is declared. The List data type...

read more
Connect to Azure Function in BC 2022 wave 2 (v21)

Connect to Azure Function in BC 2022 wave 2 (v21)

The new version of the Microsoft Dynamics 365 Business Central brought a new system module "Azure Functions" that makes integration with Azure Functions much easier and straightforward. The typical scenario, why to use Azure Functions together with Business Central,...

read more
Collectible Errors?! Is it already in use?

Collectible Errors?! Is it already in use?

Collectible Errors?! Is it already in use? This is the second part of my new article series about Collectible Errors. Let's check out the first part here: Collectible Errors?! | Microsoft Dynamics 365 - Ing. Tomáš Kapitán (kepty.cz) or you might be interested in my...

read more
Collectible Errors?!

Collectible Errors?!

Collectible Errors?! It has been already almost a year since ErrorInfo datatype & CollectibleErrors were introduced (I already have an article about basic structure: ErrorInfo data type & Collectible Errors). This article was released for the first time in...

read more
Substituting standard reports

Substituting standard reports

Report objects cannot be extended in versions previous to the Business Central 2021 release wave 1 version when ReportExtensions object was introduced. Since then, many of changes we need to do in reports can be done without creating a new copy of object. On the other...

read more

Sign Up for News

Certifications

Highest certification
Microsoft Data Management and
also in D365 Business Central

Microsoft Certified: Dynamics 365 Business Central Functional Consultant Associate

See other certifications here