Business Central 2023 wave 2 (BC23) (Namespaces in AL)

                

                                                 


Namespace syntax :

To declare a namespace in AL, you must use the namespace keyword followed by the name of the namespace. Some best practices for namespace keywords are:

A namespace should be globally unique.

The using directive :

The using directive is placed at the top of the .al file, after the namespace declaration and before any object declarations. The following example shows the order of the namespace declaration and the using directive. 
                     

This is similar to namespace in C# and other program language. More details: https://learn.microsoft.com/en-US/dotnet/csharp/fundamentals/types/namespaces

                                            

Let’s look at a simple example.

I have two variables declared in a test codeunit, one for the Customer table and one for the system codeunit Math. This is what NAV and BC developers have always done.               

     
But let’s see what happens when we add a namespace. Yes, standard objects such as tables and codeunits will not be found.

                                     

                                           


Why? In short, this is because the standard objects are not in your custom namespace, e.g. the system does not exist for SRKProject.Customer. They are in a Microsoft standard namespace.

Add ‘using Microsoft.Sales.Customer‘

                                                  

                                      


page 42 “Sales Order”:

                                       
Great improvement for all AL developers. Using namespace allows us to get away from prefix or suffix 
(Benefits and guidelines for using a prefix or suffix)

but as of now, it’s not mandatory and you can customize BC using the original way.


Please let me know your views and add your questions in the comments of this article.


Thanks & Regards
Srk.A


Comments

Popular posts from this blog

Generate QR Code in Business Central (On-Prime) Version

Download PDF Files as Compress Zip File in Business Central

Business central Sort Variables & Sort Triggers