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

BC Open Source? How to start?

BC Open Source? How to start?

BC Open Source? How to start? One of the most exciting news introduced last month in Lyon during Directions EMEA 2023 was the changes to the open-source initiative. This means that you can now contribute to the source code of the Base app and the System app, which are...

read more
Validate a FlowField Field. Wait? What?

Validate a FlowField Field. Wait? What?

Validate a FlowField Field. Wait? What? There are not many things in the AL Language that surprised me. However, last week, I found one such thing - I reviewed customizations made by another partner and had to analyze the OOTB code of the Demand Forecast matrix. I run...

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

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