Microsoft Dynamics 365 Business Central – Split Delimited Value in AL

In the AL language for Microsoft Dynamics 365 Business Central, the List Data Type represents a strongly typed list of ordered objects accessible by index. Lists are unbounded, meaning their dimension (size) is not specified when declared.

A List can only be declared with simple types (Byte, Boolean, Char, Code, Date, DateFormula, DateTime, Decimal, Text, Time, etc.) and does not support holding instantiated records.

Lists are an efficient way to create and manage unbounded data structures with many practical uses.

Only a few days pass when I do not find a reason to use lists. One of my recent uses for a List was to store and process each unique value found in a delimited text value. For this, I split the delimited text into separate values and then copied them to a new list removing duplicates.

In this example, a value delimited by a comma (‘,’) or pipe (‘|’) is split into a list of unique values.

    procedure SplitValues()
    var
        UniqueValues: List of [Text];
        DelimitedText: Text;
        value: Text;
    begin
        DelimitedText := '12,34,56,24|12,56,89,56,23|12,34,22,34';
        UniqueValues := SplitUniqueValues(DelimitedText);

        foreach value in UniqueValues do
            Message(value);
    end;

    local procedure SplitUniqueValues(DelimitedText: Text): List of [Text]
    var
        UniqueValues: List of [Text];
        Values: List of [Text];
        Delimiters: Text;
        value: Text;
    begin
        Delimiters := ', |';
        Values := DelimitedText.Split(Delimiters.Split(' '));
        foreach value in Values do
            if not UniqueValues.Contains(value) then
                UniqueValues.Add(value);

        exit(UniqueValues);
    end;

Learn more about the List Data Type Here

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

Permanent link to this article: https://www.dvlprlife.com/2023/06/microsoft-dynamics-365-business-central-split-delimited-value-in-al/

Microsoft Dynamics 365 Business Central – Recurring Purchase Lines

Businesses often order the same products and/or services from a supplier. In the many years I have been implementing Microsoft Dynamics 365 Business Central, I have frequently been asked how to add default purchase lines (often as a default G/L Account modification) to purchase documents for a vendor. Fortunately, this feature is accessible through Business Central.

Recurring Purchase Lines are useful for businesses with regular purchase documents of the same items or services from certain suppliers. By setting up recurring purchase lines, a company can automate creating these documents with predefined purchase lines, saving time and reducing the chance of errors.

To create Recurring Purchase Lines:

1. Search for recurring purchase lines using the Search of Business Central.

2. Select the Recurring Purchase Line Administration Page

3. Select the New page action (or Manage to modify or view an existing Recurring Purchase Line)

4. On the Standard Purchase Code Card, enter a code and description to reference the Recurring Purchase Line(s)

5. In the Lines group of the card, enter the lines and desired values to include for purchase documents created for an assigned vendor.

6. Enter the Line Type – you can enter Comment, G/L Account, Item, Resource, Fixed Asset, or Item (Charge) lines.

7. Enter the appropriate No. of for the line.

8. Enter a description,

9. Enter a default quantity.

10. The Amount, Variant, and Unit of Measure fields are unavailable by default; if you’d like to enter any of these values, you must personalize the page and add them.

With the Standard Purchase Codes created, they are ready to be assigned to vendors.

  1. Search for Vendors using the search feature of Microsoft Dynamics 365 Business Central.
  2. Open the Vendor List Page and navigate to the Vendor you’d like to assign Recurring Purchase Lines.
  3. Select the Related->Purchases->Recurring Purchase Lines action from the menu.
  4. Select the desired purchase code on the Vendor’s Recurring Purchase Lines List Page and specify how you want to use standard purchase codes on purchase quotes, orders, invoices, and credit memos.
    • Manual – The user can use the Get Recurring Purchase Lines action from the functions menu on the document.
    • Automatic – the Standard Purchase Code lines are added to a new purchase document. 
    • Always Ask – the user will be alerted that recurring purchase lines exist and asked to select the lines they’d like to include (if applicable)

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

Permanent link to this article: https://www.dvlprlife.com/2023/06/microsoft-dynamics-365-business-central-recurring-purchase-lines/

Microsoft Dynamics 365 Business Central – Base64 Encoding and Decoding

Base64 is a group of binary-to-text encoding schemes representing binary data in an ASCII string format. Base64 data encoding is designed to survive transport through transport layers that are not 8-bit clean, such as mail bodies. Encoding the binary data to ASCII text helps ensure that the data remains intact without loss or modification during transport.

The most common use case for base64 encoding is when binary data must be sent over text-based systems, such as email, HTTP, or complex data stored in XML or JSON.

The principle behind Base64 encoding takes 3 bytes of binary data and represents them as 4 ASCII characters. This increases the size of the data by 33%, which is a significant drawback, but sometimes this is acceptable given the benefits.

Base64 Encoding and Decoding with AL for Business Central via codeunit 4110 “Base64 Convert”. The “Base64 Convert” codeunit has many overload methods to convert text to and from its base-64 representation.

page 50100 "Base64 Encoding"
{
    ApplicationArea = All;
    Caption = 'Base64 Encoding';
    PageType = Card;

    layout
    {
        area(content)
        {
            group(General)
            {
                Caption = 'General';
                grid(Columns)
                {
                    ShowCaption = false;
                    group(text)
                    {
                        ShowCaption = false;
                        field(FromText; FromText)
                        {
                            ApplicationArea = All;
                            Caption = 'From Text';
                            Editable = true;
                            MultiLine = true;
                        }
                        field(ToText; ToText)
                        {
                            ApplicationArea = All;
                            Caption = 'To Text';
                            Editable = false;
                            MultiLine = true;
                        }
                    }
                }
            }
        }
    }
    actions
    {
        area(Promoted)
        {
            actionref(Encoderef; Encode)
            {
            }
            actionref(Dencoderef; Decode)
            {
            }
        }
        area(Processing)
        {
            action(Encode)
            {
                ApplicationArea = All;
                Caption = 'Encode';
                Image = EncryptionKeys;

                trigger OnAction()
                begin
                    ToText := Base64Convert.ToBase64(FromText);
                end;


            }
            action(Decode)
            {
                ApplicationArea = All;
                Caption = 'Decode';
                Image = Text;

                trigger OnAction()
                begin
                    ToText := Base64Convert.FromBase64(FromText);
                end;
            }
        }
    }

    var
        FromText: Text;
        ToText: Text;
        Base64Convert: Codeunit "Base64 Convert";
}

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

Permanent link to this article: https://www.dvlprlife.com/2023/05/microsoft-dynamics-365-business-central-base64-encoding-and-decoding/

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

The May 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 version 22.1 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 Updates – 22.1 (May 2023)

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

Dynamics 365 Business Central On-Premises 2022 Release Wave 1 Updates – Update 20.13 (May 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 47 (May 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)

Permanent link to this article: https://www.dvlprlife.com/2023/05/may-2023-cumulative-updates-for-dynamics-365-business-central-and-microsoft-dynamics-nav/

Real Things I’m Asked – Microsoft Dynamics 365 Business Central Copy Document

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. In Microsoft Dynamics 365 Business Central, is there a way to copy a sales document to create a new one?

A. In Microsoft Dynamics 365 Business Central, the “Copy Document” functionality allows users to create new sales or purchase documents based on existing ones. This feature can save time and effort when you need to create similar documents, such as sales orders, quotes, purchase orders, or invoices.

To use the “Copy Document” functionality in Business Central, follow these steps:

  1. Open the list page for the type of document you want to create, such as the Sales Orders or Purchase Orders list.
  2. Click on “New” to create a new document, which will be the destination document for the “Copy Document” action.
  3. Click on the “Actions” tab in the top menu in the new document.
  4. Under the “Actions” tab, click on “Functions,” and then select “Copy Document.”
  5. On the “Copy Document” request page, enter the source “Document Type” and “No.” for the document that you would like to copy from.
  6. Toggle the “Include Header” switch to indicate if the source document header should replace the destination document’s header information.
  7. Toggle the “Recalculate Lines” switch to indicate if the copied document line values are recalculated when inserted into the destination document.
  8. Modify the new document as needed.

Note that the availability and behavior of the “Copy Document” functionality might vary depending on your Business Central version, customization, or extensions.

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

Permanent link to this article: https://www.dvlprlife.com/2023/05/real-things-im-asked-microsoft-dynamics-365-business-central-copy-document/

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.

Permanent link to this article: https://www.dvlprlife.com/2023/04/microsoft-dynamics-365-business-central-al-region-directive/

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.

Permanent link to this article: https://www.dvlprlife.com/2023/04/microsoft-dynamics-365-business-central-al-conditional-preprocessor-directives/

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)

Permanent link to this article: https://www.dvlprlife.com/2023/04/april-2023-cumulative-updates-for-dynamics-365-business-central-and-microsoft-dynamics-nav/

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.

Permanent link to this article: https://www.dvlprlife.com/2023/04/dynamics-365-business-central-al-publish-full-dependency-tree-for-active-project/

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.

Permanent link to this article: https://www.dvlprlife.com/2023/04/real-things-im-asked-microsoft-dynamics-365-business-central-posting-date-is-not-within-your-range-of-allowed-posting-dates/