Business Central: know if an extension is installed

1.1k views Asked by At

In Business Central I would like to enable / disable a field in a page extension based on if a 3rd party extension is installed. I do not want to have a dependency on this 3rd party extension since most of the time it will not be present and our extension is not dependent on it.

Does anybody know what would happen if an extension is included as a dependency in the app.json but at runtime it's not installed? It's installed in the development environment but not runtime. My assumption is it will fail the installation of my extension.

For what I'm trying to do, the 3rd party extension data will not have to be updated but I would like to read it.

Is there a way to determine if a 3rd party extension is installed?

3

There are 3 answers

0
Peter Tijsma On BEST ANSWER

You could use the command:

[Ok := ] NavApp.GetModuleInfo(AppId: Guid, var Info: ModuleInfo)

Source: Microsoft Docs

It will return false if the supplied AppId is not installed, otherwise, you'll get all info about the installed app in the Info variabble.

0
JeffUK On

One option is to try and Open a table that is known to be part of the other extension.

RecordRef.Open(TableNum) will error if the other table does not exist.

Unfortunately RecordRef.Open() does not return a boolean like, e.g. Record.Get(), so we can't just do If RecordRef.Open() to test if it was sucessful.

What you therefore need is a function like the following, which, being a 'Try Function' will return a 'false' on an error, rather than actually throwing the error and stopping.

[TryFunction]
procedure CheckTableExists(reference: integer)
var
    TryRecord: RecordRef;
begin
    TryRecord.open(reference)
end;

You could then do, e.g.

trigger OnAction();
var
    CheckOtherExtensionMgt: Codeunit "CheckOtherExtensionMgt";
begin
    if CheckOtherExtensionMgt.CheckTableExists(66666) then
        Message('66666 Exists'); //Do something if the other extension does exist

    if CheckOtherExtensionMgt.CheckTableExists(27) then
        Message('27 Exists'); //Prove that processing continues even if the other extension doesn't exist
end;

When this action is processed on my environment I get a '27 Exists' message, only, replace the first message with whatever you want to do if the other extension exists

Be careful if the other extension is in the customer's object range, if so you might need to check that the table is actually the one you expected!

0
kaspermoerch On

You need to use the virtual table AllObj to determine if the table you are looking for is present:

local procedure GetValueWithoutDependency()
var
    AllObj: Record AllObj;
    RecRef: RecordRef;
begin
    AllObj.SetRange("App Package ID", [GUID of the other extension]);
    AllObj.SetRange("Object ID", [ID of the table in the other extension]);

    if not AllObj.FindFirst() then
        exit; // The table does not exist

    RecRef.Open(AllObj."Object ID"); // Won't fail because we know the table is there

    // Find your record
    // Get the field value using FieldRef
end;

Once you have the RecordRef open you set your filters to find the wanted record and then use FieldRef to get the value of the wanted field.