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

Dynamics NAV 2013 & Expired Cronus License

Dynamics NAV 2013 & Expired Cronus License

We found an interesting problem - we were not able to run the development environment for Dynamics NAV 2013. Whenever we tried to run the development client, we got the following error message: "Your program license has expired" and the development client has closed...

read more
Indirect Dependencies and Access Modifiers

Indirect Dependencies and Access Modifiers

Last week, there was a discussion on Yammer on how to get values from the "Sent Email" record when all fields are marked as Internal. I was surprised that many people do not know what can/can't access modifiers (such as local, protected, or internal) be used for. I...

read more
AL Extensions: Replace Document Attachment

AL Extensions: Replace Document Attachment

I have published a new simple, open-source extension that allows replacing existing document attachments in all master entities as well as in open documents. The source code as well as the app file that can be installed in your environment is available on my GitHub...

read more
Clean up your copied environments

Clean up your copied environments

One of the most important things every developer should handle is to clean up the environment when the environment (or a company) is copied. Especially if the environment is managed directly by a client and they can create new copies anytime. Similarly, for copied...

read more
7 git commands you should know

7 git commands you should know

For many years, developers in C/AL did not need to know anything about Git or other versioning tools. That has changed with Business Central, or more specifically with AL Language. Today, we will look at the most important (and basic) git commands any developer should...

read more
How to define the source for item reservations?

How to define the source for item reservations?

It's not uncommon to have a customer's request to limit from which source items could be reserved. For example, customers may not want to reserve items from return orders. How can we achieve this goal? It's really simple. All the magic is done in the procedure...

read more
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

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