Problem Statement:
I recently got a requirement from a customer to show an error address field “address is blank” on the customer card and that the user should not close the page until he enters the address. For this issue, I created a notification window for the user to check the missing address field.
Pre-Requisites:
- Visual Studio Code
- AL Language Extension
- Business Central
Solution:
In order to solve the above problem statement, we have to open to visual studio code and create an extension for the page on which the message needs to show the message window. In this extension, we check if the customer address is blank each time the user closes the customer card page. If the system does not find anything in the address fields then it will print the error message ‘Please Check Address’.
Kindly refer to the code below followed by the screenshot of the page extension of the customer page which contains the precise code.
Trigger OnClosePage()
Begin
IF (Address = ‘ ‘ ) then
Error (‘Please Check Address’);
End;
Once this code is deployed in Business Central and if the user forgot to fill in the address on the customer card page, he gets the following error message ‘Please Check Address’.
Once the user fills in the address information, this error message will no longer pop up in the error message in the message window and the user will be able to close the page.
Conclusion:
Thus we can easily achieve how to show an error when the address field is blank on the customer card in Business Central. Similarly, we can add a few more validations on all the pages, documents, and journals within Business Central.
Hope my solution helps resolve your problems as well!
About the author:
Vishal Talekar
Vishal Talekar is a Microsoft NAV/Dynamics 365 Business Central Technical Consultant working on languages such as CAL and AL at Direction Software LLP.