Dynamics 365 Business Central: How to get current platform version number via AL (Using codeunit 9015 “Application System Constants”)

Dynamics 365 Business Central

Hi, Readers.
I was asked a question recently, is there any easy way to get the current BC platform version number via AL?
This is an interesting question, we have previously discussed using ModuleInfo Data Type and NavApp.GetCurrentModuleInfo Method to get information about the extension that is currently running. But not BC itself. More details: Link.
So in this post, I would like to talk briefly about how to get current platform version number via AL.

First you can also think of the Base Application version number as the system version number, which is actually pretty close according to the current rules.
For example, BC20:

BC19.5:

We can simply get the version information of Base Application with NavApp.GetModuleInfo(Guid, var ModuleInfo) Method.

Source Code:

pageextension 50101 MyExtension2 extends "Customer List"
{
    trigger OnOpenPage()
    var
        Info: ModuleInfo;
        BaseAppId: Codeunit "BaseApp ID";
        VersionInfo: Label 'Version info:\\The Major Number is ''%1''.\\The Minor Number is ''%2''.\\The Build Number is ''%3''.\\The Revision Number is ''%4''.';
    begin
        NavApp.GetModuleInfo(BaseAppId.Get(), Info);
        Message(VersionInfo, Info.DataVersion.Major, Info.DataVersion.Minor, Info.DataVersion.Build, Info.DataVersion.Revision);
    end;
}

This is not the method I want to introduce this time. In fact, there is a simpler way, using codeunit 9015 “Application System Constants”.

Through this codeunit, we can directly get information such as Platform Production version. The contents of this codeunit is automatically updated with system updates. The following is the current information on the latest version of SaaS.

Let’s see more details.

Source Code:

pageextension 50101 MyExtension2 extends "Customer List"
{
    trigger OnOpenPage()
    var
        AppSysConstants: Codeunit "Application System Constants";
        VersionInfo: Label 'Version info:\\Application Version is ''%1''.\\The Build File Version is ''%2''.\\The Application Build is ''%3''.\\The Build Branch is ''%4''.\\The Platform Production Version is ''%5''.\\The Platform File Version is ''%6''.';
    begin
        Message(VersionInfo, AppSysConstants.ApplicationVersion(), AppSysConstants.BuildFileVersion(), AppSysConstants.ApplicationBuild(),
        AppSysConstants.BuildBranch(), AppSysConstants.PlatformProductVersion(), AppSysConstants.PlatformFileVersion());
    end;
}

Very simple, give it a try!!!😁

PS:
1. In NAV and older versions of BC, these version data are stored in Codeunit 1.
More details: Transitioning from Codeunit 1 to System Codeunits

2. For the method mentioned at the beginning, to get the version number of the Base Application, you can also use codeunit 457 “Environment Information” instead of ModuleInfo Data Type. There is a procedure to get the major version number of the installed app.

For example:

Source Code:

pageextension 50101 MyExtension2 extends "Customer List"
{
    trigger OnOpenPage()
    var
        BaseAppId: Codeunit "BaseApp ID";
        EnvironmentInformation: Codeunit "Environment Information";
        VersionInfo: Label 'Version info:\\The major version number of Base Application is ''%1''.';
    begin
        Message(VersionInfo, EnvironmentInformation.VersionInstalled(BaseAppId.Get()));
    end;
}

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL