How to get field values from other extensions/apps in Business Central without adding dependencies property

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about how to get field values from other extensions/apps in Business Central without adding dependencies property.

As you might know, when we develop for Business Central, we need to download the symbol file first. These contain the source code of the standard functions.

But if we want to extend other extensions, the default symbol file will not meet our needs.

Let’s see an example.
In the 2022 release wave 2, Business Central includes a redesigned Intrastat experience with extended features. More details: Set Up Intrastat Reporting

Table: Intrastat Report Setup (4810)

I want to get the value of Intrastat Contact No. field.

When we create Intrastat Report Setup (4810) table as a variable in the VS Code, the following error will be prompted.

Table ‘Intrastat Report Setup’ is missing

Yes, because it is not included in the standard symbol file.

In general, we need to add the extension info to dependencies property in the app.json file. Then download the symbol file again.

    {
      "id": "70912191-3c4c-49fc-a1de-bc6ea1ac9da6",
      "name": "Intrastat Core",
      "publisher": "Microsoft",
      "version": "21.0.46256.47234"
    }

After the download is complete, we can read the table.

Then we can easily get this value.

Is there a way to get the value without adding dependencies property? Yes, we can use RecordRef Data Type and FieldRef Data Type.
RecordRef Data Type: References a record in a table.
FieldRef Data Type: Identifies a field in a table and gives you access to this field.

In fact, this method has been available since extension V1 of NAV 2018. Since we cannot add dependencies property in extension V1, this is the only way used when reading the data in the extension.😑

For example,

Same result.

Test Video:

Source code:

pageextension 50100 CustomerListExt extends "Customer List"
{
    trigger OnOpenPage();
    var
        RecRef: RecordRef;
        FldRef: FieldRef;
    begin
        RecRef.Open(4810);
        FldRef := RecRef.Field(1);
        FldRef.SetRange();
        FldRef := RecRef.Field(7);
        if RecRef.FindSet() then
            Message(FldRef.Value);
    end;
}

PS: We can use FieldRef.SetRange([Any] [, Any]) Method to set a simple filter on a field, such as a single range or a single value.

The case mentioned above is a table in another extension, in fact, in development we encounter more often is some fields in another extension.

For example, I added a new field to the customer table in another extension (Ext A).

As in the case above, because this is not part of the standard symbol file, when I create a new extension (Ext B), I can’t read this field.

But we can also use the similar way.

Source Code:

pageextension 50100 CustomerCardExt extends "Customer Card"
{
    trigger OnOpenPage();
    var

        RecRef: RecordRef;
        FldRef: FieldRef;
    begin
        RecRef.Open(18);
        RecRef.GetTable(Rec);
        RecRef.SetRecFilter();
        FldRef := RecRef.Field(50100);
        if RecRef.FindSet() then
            Message(FldRef.Value);
    end;
}

PS: If we can get Rec, or other table variables (filtered), we can use RecordRef.GetTable(Record) Method and RecordRef.SetRecFilter() Method to set the filter, and need to re-filter the field as in the first case.
Another simple example:

Pretty simple, isn’t it? Give it a try!!!😁

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL