Microsoft Dynamics 365 Business Central – AL Region Directive

In the AL programming language, region directives are used to organize code to a specific region or section of code. Regions can help developers keep track of and manage the code for different parts of an application. The Region Directives also mark a block of code that you can expand or collapse, which is helpful with readability or focusing on sections of code.

codeunit 50101 "DVLPR Region Directive"
{
    #region Return Letters
    procedure ReturnA(): Char
    begin
        exit('A');
    end;

    procedure ReturnB(): Char
    begin
        exit('B');
    end;

    procedure ReturnC(): Char
    begin
        exit('C');
    end;
    #endregion

    #region Return Numbers
    procedure Return1(): Integer
    begin
        exit(1);
    end;

    procedure Return2(): Integer
    begin
        exit(2);
    end;

    procedure Return3(): Integer
    begin
        exit(3);
    end;
    #endregion
}

A region block is marked with the #region directive and is closed with the #endregion directive.

Note: The code and information discussed in this article is for informational and demonstration purposes only. This content was created referencing Microsoft Dynamics 365 Business Central 2023 Wave 1 online.

Microsoft Dynamics 365 Business Central – AL Conditional Preprocessor Directives

In the AL programming language, preprocessor directives are used to make code conditional, suppress warnings, and enable code expansion and collapse. The AL preprocessor directives are grouped into conditional, regions, and pragmas categories. In this article, I’ll highlight Conditional Preprocessor Directives.

Conditional preprocessor directives are a feature in AL that allows developers to include or exclude parts of the code based on certain conditions. These directives are evaluated at compile-time and help manage different configurations or enable and disable certain features.

A conditional directive checks the value of a symbol to determine if code is included in the compilation. Symbols may be defined at the beginning of a source file to set the Symbol for the scope of that file, or they can be defined in the app.json file for global scope within the extension.

Symbols are defined globally with the preprocessorSymbols setting in the extensions App.json file.

Symbols are defined with the scope of a file with the #define directive at the beginning of a source file. Symbols may also be undefined with the #undef directive, which is useful in the case of a global directive that should not be applied to a specific file.

Conditional preprocessor directives in AL for Microsoft Dynamics 365 Business Central may also use the Logical Operators “AND” and “OR,” allowing developers to include or exclude code based on multiple preprocessor symbols within one conditional directive. (Thank you for the comment, navfreak.com)

#define SYMBOL2
#define SYMBOL3
codeunit 50102 "DVLPR My Stuff"
{
    procedure CompilerDirective()
    var
        MessageTxt: Text;
    begin
#if SYMBOL1 or SYMBOL2        // Code to include if Symbol1 or Symbol2 is defined
        MessageTxt += 'Symbol1 or Symbol2\';
#endif

#if SYMBOL2 and SYMBOL3      // Code to include if Symbol2 and Symbol3 are defined
        MessageTxt += 'Symbol2 and Symbol3';
#endif

        Message(MessageTxt);
    end;


Using Conditional Preprocessor Directives is considered Best Practices for Deprecation of AL Code.

Read more about the feature Conditional directives here.

Note: The code and information discussed in this article is for informational and demonstration purposes only. This content was created referencing Microsoft Dynamics 365 Business Central 2023 Wave 1 online.

April 2023 Cumulative Updates for Dynamics 365 Business Central and Microsoft Dynamics NAV

The April updates for Microsoft Dynamics NAV and Microsoft Dynamics 365 Business Central are now available.

Before applying the updates, you should confirm that your implementation is ready for the upgrade and ensure compatibility with your modifications. Work with a Microsoft Partner to determine if you are ready and what is needed for you to apply the update.

Please note that Online customers will automatically be upgraded to Dynamics 365 Business Central 2023 Wave 1 (Version 22.0) over the coming days/weeks and should receive an email notification when upgraded.

Direct links to the cumulative updates are listed here:

Dynamics 365 Business Central On-Premises 2023 Release Wave 1 – 22.0 (April 2023)

Dynamics 365 Business Central On-Premises 2022 Release Wave 2 Updates – Update 21.6 (April 2023)

Dynamics 365 Business Central On-Premises 2022 Release Wave 1 Updates – Update 20.12 (April 2023)

Dynamics 365 Business Central On-Premises 2021 Release Wave 2 Updates – Update 19.18 (April 2023)

Dynamics 365 Business Central On-Premises 2021 Release Wave 1 Updates – Update 18.18 (October 2022)

Dynamics 365 Business Central On-Premises 2020 Release Wave 2 Updates – Update 17.17 (April 2022)

Dynamics 365 Business Central On-Premises 2020 Release Wave 1 Updates – Update 16.19 (January 2022)

Dynamics 365 Business Central On-Premises 2019 Release Wave 2 Updates – Update 15.17 (April 2021)

Dynamics 365 Business Central On-Premises Spring 2019 Updates – Update 46 (April 2023)

Dynamics 365 Business Central On-Premises October’18 Updates – Update 18 (April 2020)

Microsoft Dynamics NAV 2018 – Update 60 (January 2023)

Microsoft Dynamics NAV 2017 – Update Update 61 (January 2022)

Microsoft Dynamics NAV 2016 – Update 67 (July 2021)

Dynamics 365 Business Central – AL: Publish full dependency tree for active project

Dynamics 365 Business Central 2022 Wave 1 introduced a feature for working with workspaces and dependencies. Developers using runtime version 9.0 or higher can use the exciting feature Publish full dependency tree for active project.

The AL: Publish full dependency tree for active project command will traverse a project dependency graph in the workspace and install any required projects if these aren’t already deployed. The command will calculate the correct order in which to compile and publish the dependencies of the current project and publish them using the launch.json option selected from the currently active project.

Only project and application references within the scope of the workspace will be traversed. In cases where the deployed AL project has dependencies on applications not within the current workspace, they must be installed and deployed beforehand.

How does this work? For example, I have a workspace containing four apps – App1, App2, App3, and App4. For those apps, App2 and App3 depend on App1, and App4 depends on App3. Previously, the apps had to be manually deployed in a hierarchical order to ensure the dependency was installed before the app that references it.

The full dependency tree is automatically discovered and published:

Note: The code and information discussed in this article is for informational and demonstration purposes only. This content was created referencing Microsoft Dynamics 365 Business Central 2022 Wave 1 online.

Real things I’m asked – Microsoft Dynamics 365 Business Central Posting Date is not within your range of allowed posting dates


I am asked many questions about Business Central on any given day. The questions vary and cover various topics, from development to administration to integration to general application use, to name a few. I want to post them all, but that is not feasible; From time to time, I pick one to write about.

Q. A user received the error “Posting Date is not within your range of allowed posting dates.” How do I set a user’s posting date range of allowed?

A. In Microsoft Dynamics 365 Business Central, the posting date range defines the valid period for financial transactions to be posted in the general ledger.

Usually, the posting date range is set for a fiscal year or accounting period, but it can also be a specific time frame that suits an organization’s needs.

During the posting process of a financial transaction, the procedure IsPostingDateValidWithSetup, found in “User Setup Management,” checks to confirm that a posting date is within the range of the user’s posting date range.

With a quick look at the code for checking the date, I know you wanted to see it. We can see if a User Setup record exists with a date range, then the posting date must fall within that range. If there isn’t a User Setup record, with a date range, for the user, then the date range found on the General Ledger Setup is used.


procedure IsPostingDateValidWithSetup(PostingDate: Date; var SetupRecordID: RecordID) Result: Boolean
var
    UserSetup: Record "User Setup";
    AllowPostingFrom: Date;
    AllowPostingTo: Date;
    IsHandled: Boolean;
begin
    OnBeforeIsPostingDateValidWithSetup(PostingDate, Result, IsHandled, SetupRecordID);
    if IsHandled then
        exit(Result);

    if UserId <> '' then
        if UserSetup.Get(UserId) then begin
            UserSetup.CheckAllowedPostingDates(1);
            AllowPostingFrom := UserSetup."Allow Posting From";
            AllowPostingTo := UserSetup."Allow Posting To";
            SetupRecordID := UserSetup.RecordId;
        end;
    if (AllowPostingFrom = 0D) and (AllowPostingTo = 0D) then begin
        GLSetup.GetRecordOnce();
        GLSetup.CheckAllowedPostingDates(1);
        AllowPostingFrom := GLSetup."Allow Posting From";
        AllowPostingTo := GLSetup."Allow Posting To";
        SetupRecordID := GLSetup.RecordId;
    end;
    if AllowPostingTo = 0D then
        AllowPostingTo := DMY2Date(31, 12, 9999);
    exit(PostingDate in [AllowPostingFrom .. AllowPostingTo]);
end;

If you’d like to specify a Posting Date range for a specific user, create (or modify if it exists) a User Setup and populate the “Allow Posting From” and/or the “Allow Posting To” value. Note: If you fill in only one of the values, then that end of the range has no limit.

To set the Posting Date range for those that do not have a User Setup date range defined, populate the “Allow Posting From” and/or the “Allow Posting To” on the General Ledger Setup. Note: As with the User Setup range, if you fill in only one of the values, then that end of the range has no limit.

Microsoft Dynamics 3655 Business Central – Create a New Company

A company in Microsoft Dynamics 365 Business Central refers to an independent entity that conducts business operations and financial transactions. It can be a legal entity, such as a corporation, limited liability company (LLC), or an operational entity within a larger organization.

In Microsoft Dynamics 365 Business Central, a company is set up as a separate entity with its chart of accounts, general ledger, and other financial and operational settings. It can have its customers, vendors, items, and other master data specific to its operations.

Microsoft Dynamics 365 Business Central allows you to manage multiple companies within a single environment, enabling you to consolidate financial data and perform intercompany transactions. Note: You can switch between companies through My Settings or the environment designator.

A new company is added to Business Central through the assisted setup for creating a company.

  1. Search for Companies using the “Tell Me” Search within Microsoft Dynamics 365 Business Central.
  2. Select Companies List Page
  3. On the Companies Page, select the Create New Company action item from the New Menu in the Action Bar
  4. Walk through the steps of the assisted setup for creating a company
  5. Enter a name for the company and select the data used to get started with your new company.
    Evaluation – Sample Data
    Essential Experience / Cronus Company Sample Data / Setup Data
    Create a company with the Essential functionality scope containing everything you need to evaluate the product for companies with standard processes. For example, sample invoices and ledger entries allow you to view charts and reports. You can use the company to try out the product for as long as you want. You can  install the Contoso Coffee Demo Data app on top of the default sample data for various manufacturing demonstration scenarios. 
    Production – Setup Data
    Only Essential Experience / Setup Data Only
    Create a company with the Essential functionality scope containing data and setup, such as a chart of accounts and payment methods ready for use by companies with standard processes. Set up your items and customers, and start posting right away. You will be able to use this company for a 30-day trial period.
    Create New – No Data
    Any Experience / No Sample Data / No Setup Data
    Create a company with the desired experience for companies with any process complexity, and set it up manually. You will be able to use this company for a 30-day trial period.
  6. Manage users of the new company Add users to or remove users from the new company.
  7. Finish the assisted setup to create your new company

Your new company may take a few minutes to initialize. Once initialization is complete, you can switch to your new company to being processing data.

Note: The code and information discussed in this article is for informational and demonstration purposes only. This content was created referencing Microsoft Dynamics 365 Business Central 2023 Wave 1 online.

Real things I’m asked – Microsoft Dynamics 365 Business Central Copy Company Data to a New Company

Q. How do I copy data from one Business Central company to another?

A. Microsoft Dynamics 365 Business Central offers a couple of options to copy data from one company to another.

Copy Company

One option creates a complete copy of a company into a new company in the same environment. 

  1. Search for Companies using the “Tell Me” Search within Microsoft Dynamics 365 Business Central.
  2. Select Companies List Page
  3. On the Companies Page, select the company you want to copy into a new one.
  4. Select the Copy Menu Item from the Action Bar
  5. Enter the New Company Name on the Copy Company Dialog.
  6. Read the IMPORTANT note about copying a company and performance. Confirm the “I understand” button if you are comfortable proceeding.
  7. Click Ok
  8. When the copy company action is complete, a confirmation dialog will appear.

Configuration Worksheet

A second option, which allows for a more selective way to copy data,  is to use a Configuration Worksheet.

  1. Switch to the company that you would like to copy data into from another company in the environment.
  2. Search for Configuration Worksheet using the “Tell Me” Search within Microsoft Dynamics 365 Business Central.
  3. Select the Configuration Worksheet Task
  4. On the Configuration Worksheet, enter the tables from which you want to copy data into the current company. You can manually enter the tables or use the Get Tables menu action from the Prepare Action Bar item for more options to add multiple tables.
  5. Select the “Copy Data from Company” menu item from the Prepare Actions menu.
  6. On the Copy Company Data Page, select the tables that you would like to copy data from and select the Copy Data action item.
    Note: Data can only be copied from a source table that has records into a destination table that does not have records
  7. Click Yes to copy the data for the selected tables

Note: The code and information discussed in this article is for informational and demonstration purposes only. This content was created referencing Microsoft Dynamics 365 Business Central 2023 Wave 1 online.

Real things I’m asked – Business Central hide the warning when you close a document that you have not posted

Q: How do I hide the warning that I have not posted a sales document when closing it?

A. You may have seen the warning and been annoyed with it. The nuisance dialog appears and asks to confirm that you want to close an order that has not been posted – 

The document has been saved but is yet posted. Are you sure you want to exit? 

Great feature?!? I say No.

That pesky warning message is managed by the “Warn about posted documents” setting on the My Notifications Page. The warning can be disabled entirely or configured to display for specific document types by specifying a condition.

While it’s open, look at some of the other notification settings.

Note: The code and information discussed in this article is for informational and demonstration purposes only. This content was created referencing Microsoft Dynamics 365 Business Central 2022 Wave 2 online.

March 2023 Cumulative Updates for Dynamics 365 Business Central and Microsoft Dynamics NAV

The March updates for Microsoft Dynamics NAV and Microsoft Dynamics 365 Business Central are now available.

Before applying the updates, you should confirm that your implementation is ready for the upgrade and ensure compatibility with your modifications. Work with a Microsoft Partner to determine if you are ready and what is needed for you to apply the update.

Please note that Online customers will automatically be upgraded to 21.5 over the coming days/weeks and should receive an email notification when upgraded.

Direct links to the cumulative updates are listed here:

Dynamics 365 Business Central On-Premises 2022 Release Wave 2 Updates – Update 21.5 (March 2023)

Dynamics 365 Business Central On-Premises 2022 Release Wave 1 Updates – Update 20.11 (March 2023)

Dynamics 365 Business Central On-Premises 2021 Release Wave 2 Updates – Update 19.17 (March 2023)

Dynamics 365 Business Central On-Premises 2021 Release Wave 1 Updates – Update 18.18 (October 2022)

Dynamics 365 Business Central On-Premises 2020 Release Wave 2 Updates – Update 17.17 (April 2022)

Dynamics 365 Business Central On-Premises 2020 Release Wave 1 Updates – Update 16.19 (January 2022)

Dynamics 365 Business Central On-Premises 2019 Release Wave 2 Updates – Update 15.17 (April 2021)

Dynamics 365 Business Central On-Premises Spring 2019 Updates – Update 45 (March 2023)

Dynamics 365 Business Central On-Premises October’18 Updates – Update 18 (April 2020)

Microsoft Dynamics NAV 2018 – Update 60 (January 2023)

Microsoft Dynamics NAV 2017 – Update Update 61 (January 2022)

Microsoft Dynamics NAV 2016 – Update 67 (July 2021)

Dynamics 365 Business Central 2023 Wave 1 – Attach AL debugger to active session or next session

With each update of Dynamics 365 Business Central, Microsoft enhances what is often referred to as the base application and enhances the development environment. Dynamics 365 Business Central 2023 Wave 1 has several exciting Development features for runtime 11.0. One of the exciting features is to Attach AL debugger to active session or next session.

In any development environment, debugging is one part of the development lifecycle. Developing in AL for Microsoft Dynamics 365 Business Central is no different.

What is debugging?

Debugging is finding and resolving errors or defects within a computer program. Debugging aims to identify and fix bugs, which are issues or problems that prevent the program from functioning as intended. Debugging is an essential part of the software development process, as it ensures that the program is working correctly and meets the requirements of the end users.

Debugging can involve various techniques and tools, including step-by-step execution, logging, tracing, and testing. Developers use debugging tools such as debuggers, profilers, and log analyzers to help identify and resolve issues within the code. They may also use code review and collaboration tools to help identify and resolve problems.

Debugging helps the program runs efficiently, accurately, and as intended. By carefully identifying and fixing bugs, developers can improve the quality and reliability of their software.

Debugging Microsoft Dynamics 365 Business Central

AL Developers can debug code execution in Business Central by attaching a session to a specified server and awaiting a process to trigger your set breakpoint or the trigger of an error. Then debugging starts when the code on which the breakpoint is executed or a statement generates an error.

To activate the attach functionality, you need to create a new configuration in the launch.json file. This configuration comes in two flavors: Attach to the next client on the cloud sandbox and Attach to the next client on your server. If you want to attach to a cloud session, use the first option; if you’re going to attach to a local server, use the second option.

In the attach configuration, the breakOnNext setting specifies the next client to break on when the debugging session starts and allows only one option. The available options are: WebServiceClient, WebClient, and Background. The example below illustrates a configuration for a local server.

New Debugging Microsoft Dynamics 365 Business Central 2023 Wave 1

Starting with Microsoft Dynamics 365 Business Central 2023 Wave 1, two new settings, userId, and sessionID, were added to the launch.json configuration allowing you to specify a session ID to attach to an existing session or a user ID to attach to the next session for that user. These new settings allow the standard AL debugger to connect to a currently running session or the next session for the specific user.

Read more about the feature Attach AL debugger to active session or next session here.

Read more about debugging in AL for Microsoft Dynamics 365 Business Central here.

Note: The code and information discussed in this article is for informational and demonstration purposes only. This content was created referencing Microsoft Dynamics 365 Business Central 2023 Wave 1 online.