Segment AL code and reduce naming conflicts with namespaces


This content is archived and is not being updated. For the latest documentation, go to What's new or changed in Business Central. For the latest release plans, go to Dynamics 365, Power Platform, and Cloud for Industry release plans.

Enabled for Public preview General availability
Admins, makers, marketers, or analysts, automatically Aug 17, 2023 Oct 2, 2023

Business value

AL for Business Central will now support namespaces, similar to other code languages. Namespaces provide a way of organizing objects and code in a logical and hierarchical manner. 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.

Feature details

An AL file can now define a namespace at the top, which will apply to all objects in the code file. A given object can only belong to one namespace, but the same namespace can be used for multiple AL files and objects.

When objects are resolved, the closest scope is used first. Therefore, to resolve to a similarly named object in a dependent extension, the reference must use a fully qualified name. Alternatively, it's possible to define using directives to include external namespaces and thereby omit fully qualifying names.

Because namespaces are useful for logical segmentation of extensions, the AL Explorer also shows namespaces for objects and allows grouping objects by namespace, making it easier to discover related objects, focus on app subareas, and identify inconsistencies when adding new objects.

Nested namespaces provide better naming of objects than expressing the full structure in the 30-character object name. However, renaming existing objects is a breaking change, so this capability mainly helps with the logical structure of existing objects and new names going forward.

Code actions will be available to help developers add namespaces to existing sources.

Here are some examples, first on defining namespace in code.

Example of defining namespace in system apps entity text table

Then on how you can include objects in other namespaces in your scope to use them.

Example of including objects in other namespaces via Using to access in code, here in a Customer table

Finally, here is an example of base app objects grouped by namespace, with Customer table residing in the Microsoft.Sales.Customer namespace. Grouping objects by namespace like this makes it easier to focus on and find related objects.

Example of base app objects grouped by namespace

See also

Namespaces in AL (docs)