NameSpaces in Business central D365
Introduction
Namespaces help avoid name conflicts that can arise from combining libraries by grouping code into logical groupings and hierarchies. Namespaces give the code base structure, which facilitates navigation and comprehension, guarantee uniqueness in code names, and permit name reuse in many situations. Numerous computer languages employ namespaces, and Business Central provides them with AL from Business Central 2023 wave 2 (BC23).
Table Customer
All objects in the code file belong to the namespace that is declared at the beginning of an AL file.
Pre-requisites
Business Central onCloud
References
Configuration
They can be used to help avoid naming conflicts between different extensions, making it easier to maintain and understand extensions, including the relationship between different objects.
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 first part of a namespace is tied to the developing organization or an individual, followed by a product name, and logical grouping within the product, such as, for example, namespace BigCompany.SmartProduct.SomeProductArea. This supports the two purposes of namespaces – object name unique and logical grouping of related functionality.
- Use a stable and nonversion specific name for the namespace. Changing the name of a namespace is a breaking change.
- The namespace name can be any valid AL identifier, and it can contain dots to indicate a hierarchy of namespaces.
Example: namespace DevOrg.Client.SpecificModule;
You can use the same namespace declaration in other.al files to declare multiple objects in the same namespace. The same namespace is shared by all code files that employ the same namespace declaration.
If you try to utilize an object after namespaces have been declared, an error will occur.
Example:
The error will be fixed after declaring a keyword with namespace name.
Conclusion
At first glance, namespaces appear superfluous and confusing, but as you use them, you’ll realize their true value and realize they’re not that complicated after all. Give them a try.
These are all excellent practices that Microsoft supports as well.
We hope you found this article useful, and if you would like to discuss anything, you can reach out to us at [email protected]