Namespaces are increasing to grow in relevance in Business Central AL. If you have avoided the use of names spaces to this date, get the back story here:

Business Central release 28 adds a few new features to the namespace system that can be really helpful. Remember the goal of namespaces is to keep things clear as to where the object is coming from.

Here is the old way of calling a page:

using Microsoft.Sales.Customer;

#Somewhere further down the code
Page.Run(Page::"Customer Card");
Page.RunModal(Page::"Customer Card");

This is all well and good, you have the using reference at the top of the code for the Namespace that contains the Customer Card page, and you call it down below in your page reference.

This issue here is that the goal of a namespace is to keep things clear. If the namespace is at the top of the page, and you have two procedures with similar or identical names it is difficult to keep them seperate.

Now we can run a page with a fully qualified name:

Page.Run(Microsoft.Sales.Customer."Customer Card");
Page.RunModal(Microsoft.Sales.Customer."Customer Card");

I don’t need the namespace at the top of the file, and we are explicit as to where this page is coming from. It is clearer at the line level, I can’t always see all my using statements. In some of my larger code units, it would hardly leave me any space for the code.

Same rules apply to Code Units.

Old Method requiring a namespace.

Using Microsoft.Sales.Posting;

Codeunit.Run(CODEUNIT::"Sales-Post (Yes/No)");

With a Fully Qualified Name.

CodeUnit.Run(Microsoft.Sales.Posting."Sales-Post (Yes/No)");

What about reports you ask? Fully Qualified Names supported:

REPORT.Run(Microsoft.Sales.Reports."Cash Applied", true, true, CustLedgerEntry);
Report.RunModal(Microsoft.Sales.Reports."Cash Applied", true, true, CustLedgerEntry);
Report.Execute(Microsoft.Sales.Reports."Cash Applied", true, true, CustLedgerEntry);

If you only needed Microsoft.Sales.Reports for this single Cash Applied report, then using the Fully Qualified Name is better than a Using statement.

Lastly we have the Record Ref. If you haven’t had the opportunity to take a look at this powerful object, you can read about it here.

The change here is that if we wanted to create a record ref to the customer table we can use the Fully Qualified Name.

procedure UpdateCustomer(Blocked: Boolean)
var
    CustomerRef: RecordRef;
    FieldRef: FieldRef;
begin
    CustomerRef.Open(Microsoft.Sales.Customer.Customer);
    CustomerRef.FindFirst();
    FieldRef := CustomerRef.Field(39); // Assuming field 39 is the "Blocked" field
    FieldRef.Value(true);
    CustomerRef.Modify()
end;

You can see on line 6 we open the customer table with the Fully Qualified Name of the customer table. The rest of the code blocks the first customer in the table.

Typically, I would end with, for more information checkout the Microsoft Learn page. You are welcome to click, but the 2 sentences they provided don’t grant much additional details.

Leave a comment

Trending