Diagram showing Extension 1 and Extension 2 databases connected without a direct dependency, both linked through Microsoft Dynamics 365 Business Central.

Modify data in Extensions without dependency

2 min read

Have you ever needed to access or modify data from another extension without having a dependency on it?

If your goal is simply to access or modify table data, you’re in the right place. However, if you need to change the logic of third-party extensions, unfortunately, this still requires a dependency on that third-party application.

Two independent extensions in Business Central, only one of which owns the table fields, with no dependency between them

Let’s explore an example involving two separate and independent extensions in Business Central. The first extension includes a table extension on the Customer record, adding two new fields.

A table extension on Customer adding the fields MyField 1 and MyField 2

It also extends the Customer Card page to include these fields after the Name field.

The matching page extension putting both fields after Name on the Customer Card

The same page extension source

To illustrate, we’ll populate MyField1 with a value.

The Customer Card with VALUE1 entered in MyField 1 and MyField 2 left blank

Next, we’ll create a completely new extension without any dependencies.

app.json for the second extension, its dependencies array deliberately empty

This new extension includes a page extension on the Customer Card and an OnOpenPage trigger to retrieve the value of MyField 1.

An OnOpenPage trigger reading field 50100 through RecordRef and FieldRef

As shown, we include an additional check to verify if the field with the specified ID exists to prevent errors if the corresponding app is not installed. Additionally, you can use the Extension Management Codeunit to check if a specific application is installed.

The same trigger guarded by Extension Management IsInstalledByAppId before it touches the field

It is crucial to obtain the correct field ID, which you can find by inspecting the page on the Customer Card Page.

Page Inspection on the Customer Card, showing field IDs 50100 and 50101 and which extension owns them

After publishing Extension 2, we can check the Customer Card page to confirm that we have successfully read the value of a field that is not part of our extension.

The Customer Card showing the message MyField 1 value is VALUE1, read without a dependency

You have successfully read the value of the field which is not in your extension!

Now, let’s move on to modifying data.

The trigger rewritten to set field 50101 through FieldRef and call RecRef.Modify

The Customer Card with MyField 2 now reading EXTENSION 2, written by the second extension

Upon opening the Customer Card, MyField 2 gets a value.

The Power of RecordRef****

RecordRef offers a lot of possibilities. In the same way that we obtained and modified a field value using FieldReference, we can perform similar actions with records stored in third-party extensions.

A RecordRef loop over a third-party table, using SetLoadFields and reading two fields by ID

For instance, with RecordRef, we can use SetLoadFields to ensure our code is performance-optimized. We can then open a custom table with ID 50100, loop through it, and execute our code.

As you can see, RecordRef provides numerous possibilities.

Procedures on RecordRef which you can use:

RecordRef IntelliSense, from AddLink through CountApprox

RecordRef IntelliSense, from CurrentKey through FilterGroup

RecordRef IntelliSense, from Find through HasLinks

RecordRef IntelliSense, from Init through Modify

RecordRef IntelliSense, from Next through SetLoadFields

You can read more regarding RecordRef on Microsoft Learn: RecordRef Data Type – Business Central | Microsoft Learn

This also means that we can attach to some business processes such as Sales Posting routine and during posting fill out some of the third party fields differently or extract their value, all that without having any dependency on it.

All of this is great, but as we mentioned in the beginning if you need to modify the business processes, meaning, codeunit code, or subscribing to custom publishers on a third party extension is not possible without dependencies on that app.

Despite this limitation, I hope this article helps resolve some issues related to dependencies on third-party extensions.

Related posts

Comments

    Leave a comment

    Reviewed before it appears.