A Non-Dependency Approach to BC Extension Dependencies

With the shift to extension development since BC, developers now have an option to have one big extension or to have multiple smaller extensions that are dependent with others.

Both options definitely have pros and cons. However, I have seen people avoiding the dependencies all together only because it brings complexity to the development and the publishing process.

I recently had a case where there were two independent extensions and a new dependency requirement showed up unexpectedly. The requirement was pretty simple: get a value from Extension A to Extension B.

The obvious choice was to create an extension dependency. However, I didn’t want to introduce dependency to my extensions because the requirement was too small to justify using the dependency.

So, how to solve this without declaring dependencies ? This is where Codeunit.Run comes in.

[Ok := ]  Codeunit.Run(Number: Integer [, var Record: Record])

With Codeunit.Run, you can call a codeunit in the other extension without declaring the extension dependencies. You can also pass a record to interact with the other extension.

Example

Imagine if you have an extension A that add “Description 2” field to G/L Entry. Now, you want to get that Description 2 from extension B.

In extension A, create a codeunit field to retrieve the record and return the value to extension B. You can use any standard table, such as Excel Buffer, Data Exchange, Purchase Header, etc. We are going to use G/L Entry for this example.

codeunit 50001 “Connector”

{

TableNo = “G/L Entry “;

Description = ‘Exchange Information with other Extension’;

trigger OnRun()

begin

Description := ”;

Description := “Description 2″;

end;

}

In extension B, you can call that codeunit to get the value.

local procedure GetGLDescription2(GLEntry: Record ” G/L Entry”): Text

    begin     

      If Not Codeunit.Run(50001,GLEntry) then

        exit(”);

      exit(GLEntry.Description); //Description has been replaced with Description 2 from extension A

    end;

This approach works without declaring any dependencies between the two extensions. Both extensions are still independent and you can publish / unpublish the other without worrying about the other extension.

thatnavguy

Experienced NZ-based NAV Developer and Consultant with 15+ years of experience leading multiple IT projects, performing business analyst, developing, implementing, and upgrading Dynamics NAV and Business Central. Passionate to deliver solution that focuses on user-friendly interface while keeping high standard of compliance with the needs.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *