Dynamics 365 Business Central: How to get Extension Package ID from App ID in AL

Dynamics 365 Business Central

Hi, Readers.
Today I would like to briefly talk about how to get Extension Package ID from App ID in AL.

App ID is the unique ID of the extension. When the app.json file is automatically created, the ID is set to a new GUID value. (Should uniquely identify the application and remains static across versions.)

SettingExampleDescription
id"id": "ef4dabfc-1de7-4d90-b948-4a9c2933d794"The id, also known as the app ID. This is a GUID, which is autogenerated when the project is created. The app ID is also bound to how tables are named in Business Central and how the identity of an application is computed. Changing the app ID might have severe consequences, such as the app not functioning properly, or data not being available.

For more settings, see JSON files.

What is Package ID? You can find the answer in table 2000000206 “Published Application”.
Package ID: The package identifier. Belongs to the input package and is uniquely generated upon compiling.

The Package Id of the same app is different in different environments and is not saved in app.json file.
Sandbox242:

SandboxUS240:

In how to list all installed extensions/apps in your Business Central environment (Including hidden apps – “_Exclude_……”), we mentioned that some standard functions use Package ID.
For example, we can use the UninstallExtension() method in codeunit 2504 “Extension Management” to uninstall extensions in Business Central.

Source Code:

    /// <summary>
    /// Uninstalls an extension, based on its PackageId.
    /// </summary>
    /// <param name="PackageId">The ID of the extension package.</param>
    /// <param name="IsUIEnabled">Indicates if the uninstall operation is invoked through the UI.</param>
    /// <returns>True if the extention is uninstalled successfully; false otherwise.</returns>
    procedure UninstallExtension(PackageId: Guid; IsUIEnabled: Boolean): Boolean
    begin
        exit(ExtensionInstallationImpl.UninstallExtension(PackageId, IsUIEnabled));
    end;

First, find out the Package ID using the method mentioned above.

Then I created an extension to uninstall it.

It was successfully uninstalled.

So can we get this Package ID from App ID in AL? Yes. There are three simple ways.

1. Using the standard method, codeunit 2504 “Extension Management” -> procedure GetCurrentlyInstalledVersionPackageIdByAppId

For example, Base Application: 437dbf0e-84ff-417a-965d-ed2bb9650972

Test code:

pageextension 50207 ZYCustomerListExt extends "Customer List"
{
    trigger OnOpenPage()
    var
        ExtensionMgt: Codeunit "Extension Management";
    begin
        Message(Format(ExtensionMgt.GetCurrentlyInstalledVersionPackageIdByAppId('437dbf0e-84ff-417a-965d-ed2bb9650972')));
    end;
}

2. Using table 2000000153 “NAV App Installed App”

Test code: The result is the same as method 1.

pageextension 50207 ZYCustomerListExt extends "Customer List"
{
    trigger OnOpenPage()
    var
        NAVAppInstalledApp: Record "NAV App Installed App";
    begin
        if NAVAppInstalledApp.Get('437dbf0e-84ff-417a-965d-ed2bb9650972') then
            Message(Format(NAVAppInstalledApp."Package ID"));
    end;
}

More details: Dynamics 365 Business Central SaaS: How to get the list of Extension ID (App ID), Extension Name, Publisher, etc. via AL

3. Using NavApp Data Type and ModuleInfo Data Type

Test code: The result is the same as method 1.

pageextension 50207 ZYCustomerListExt extends "Customer List"
{
    trigger OnOpenPage();
    var
        Info: ModuleInfo;
    begin
        NavApp.GetModuleInfo('437dbf0e-84ff-417a-965d-ed2bb9650972', Info);
        Message(Format(Info.PackageId));
    end;
}

Very simple, give it a try!!!😁

PS:
1. Dynamics 365 Business Central: View the all object details (Type, ID, Name…) and find out what extension an object belong to without using VS Code

2. Dynamics 365 Business Central: How to get information about the extension that is currently running (ModuleInfo Data Type and NavApp.GetCurrentModuleInfo Method)

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL