Lab Notes #1

I have two clients with very similar requirements, except one has a third-party extension that adds a few field requirements. I don’t want to maintain two extensions, one with the dependency and one without. Here is how we can have an optional extension interaction.

In this example I’m creating General Journals with an optional interaction with Binary Stream Multi-Entity Management. I only need two fields from the Binary Stream extension, so I’ve broken the General Journal creation down into two steps, Core and Extension Fields.

procedure PostEntityCashTransfer(EntityCashTransferRec: Record TMG_EntityCashTransfer)
    var
        Journal: Record "Gen. Journal Line";
        JournalRecordRef: RecordRef;
        BssiEntityID: FieldRef;
        BssiOriginalEntityID: FieldRef;
        Info: ModuleInfo;
        LineNo: Integer;
    begin

        LineNo := GetNextNumber('GENERAL', 'DEFAULT');
        // Create G/L Entry for Source Entity (Credit)
        Journal.Init();
        Journal."Line No." := LineNo;
        Journal."Journal Template Name" := 'GENERAL';
        Journal."Journal Batch Name" := 'DEFAULT';
        Journal."Posting Date" := '12/25/2025';
        Journal."Account Type" := Journal."Account Type"::"G/L Account";
        Journal."Shortcut Dimension 1 Code" := '5516';
        Journal."Shortcut Dimension 2 Code" := '2347';
        Journal."Account No." := '2637';
        Journal.Description := 'Basic Journal Entry';
        Journal."Document No." := 'Test Doc 1;
        Journal.Amount := 500;
        Journal.Insert(true);

        //Check for Binary Stream MEM installation to set BssiEntityID and BssiOriginalEntityID fields
        if NavApp.GetModuleInfo('e7e4551c-46e4-40a0-98aa-d33dc1d10bde', Info) then begin
            JournalRecordRef.GetTable(Journal);
            BssiEntityID := JournalRecordRef.Field(70210826); // BssiEntityID
            if BssiEntityID.Active then
                BssiEntityID.Value := '5516';

            BssiOriginalEntityID := JournalRecordRef.Field(70210833); // BssiOriginalEntityID
            if BssiOriginalEntityID.Active then
                BssiOriginalEntityID.Value := '2347';
            JournalRecordRef.Modify(true);
        end;
end;

Lines 13-25 are a basic General Journal insert statement. Nothing to tricky there.

On line 28 we check if the Binary Stream MEM extension is installed. Note the GUID matches the one in Business Central Extension Management.

We use the NavApp.GetModuleInfo to check if an Extension with that ID has been installed. If it has then it returns a true, else a false. If you don’t have a test condition, it errors. We now know that the Extension has been installed and we should handle the field.

Line 29 generate a Record Ref of our Journal.

Line 30 generates a Field Ref using the Field ID. I retrieved the Field ID from Page Inspection.

Line 31 checks that the field is active. Line 32 sets the value. This process is repeated for the second field we needed to set. Lastly the Record Ref has it’s Modify procedure called.

Now if we run this code without Binary Stream MEM installed, then it runs as expected. In the case the Binary Stream MEM is installed, then the additional fields are updated.

There is no dependency on Binary Stream MEM in the App.JSON, so this can be installed into systems both with and without that extension. If the extension is installed at a later date, then the system will automatically run the additional code.

Let me know in the comments if you’ve used this technique to escape a dependency or if you plan to in the future. Subscribe to the BLOG so you are notified of the latest posts.

Leave a comment

Trending