One more article about ErrorInfo data type. Have you already read my previous posts about ErrorInfo and Collectible Errors?
- ErrorInfo data type & Collectible Errors | MSDyn365 Business Central – Ing. Tomáš Kapitán (kepty.cz)
- Collectible Errors?! | MSDyn365 Business Central – Ing. Tomáš Kapitán (kepty.cz)
- Collectible Errors?! Is it already in use? | MSDyn365 Business Central – Ing. Tomáš Kapitán (kepty.cz)
- Error actions for ErrorInfo data type | MSDyn365 Business Central – Ing. Tomáš Kapitán (kepty.cz)
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;