Dynamics 365 Business Central: Can we access the standard internal table/field (Access Property = Internal) via AL???

Dynamics 365 Business Central

Hi, Readers.
Today I’d like to talk briefly about whether or not we have access to the standard internal table/field (Access Property = internal) via AL.

Access modifiers are used to set accessibility of tables, table fields, codeunits, and queries, etc which controls whether the object can be used from other code in your module or other modules. You can set the object accessibility by using the Access Property. If the Access property isn’t specified; default is Public.

Access Property: Sets the object accessibility level, which controls whether the object can be used from other code in your module or other modules.

Property Value:

ValueAvailable or changed withDescription
Publicruntime version 1.0The object can be accessed by any other code in the same module and in other modules that references it.
Internalruntime version 1.0The object can be accessed only by code in the same module, but not from another module.

For exmaple, table 9008 “User Login”

Table field level: For table fields there are two additional settings for Access and you have the following settings available

Access modifierLevel of accessibility
LocalThe field can be accessed only by code in the same table or table extension where the field is defined.
ProtectedThe field can be accessed only by code in the same table or table extensions of that table.
PublicThe object can be accessed by any other code in the same module and in other modules that references it. It is the default value.
InternalThe object can be accessed only by code in the same module, but not from another module.

For example, Internal fields (Message Id, Account Id, Connector) in table 8888 “Email Outbox”

When we try to access the internal table via AL, the following error will be prompted.

‘User Login’ is inaccessible due to its protection level ALAL0161

Similar to the above, when we try to access the internal field via AL, the following error will be prompted.

‘”Message Id”‘ is inaccessible due to its protection level ALAL0161

So can we access this standard internal table or fields?
In conclusion, we can only access the internal fields, but if the table is set with the Internal property, it cannot be accessed. Let’s see more details.

For example, I need to find out the “Message Id” with “Id” as 3 in table 8888 “Email Outbox”.

Since there are internal fields in this table, if we try to open the table directly through the URL, this will prompt insufficient permissions error.

Sorry, the current permissions prevented the action. (TableData Email Outbox Read: )

But here is a little trick, we can use RecordRef Data Type and FieldRef Data Type to access.
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.

This is similar to the method mentioned when we discussed How to get field values from other extensions/apps in Business Central without adding dependencies property

So we can do as follows.

Looks good.

PS: If you do not add the Permissions Property, the following error will also be displayed.

Permissions = tabledata "Email Outbox" = r;

Sorry, the current permissions prevented the action. (TableData Email Outbox Read: ZY Test Ext)

Source Code:

pageextension 50110 ZYItemListExt extends "Item List"
{
    trigger OnOpenPage()
    var
        ZYCodeunit: Codeunit "ZYCodeunit";
    begin
        ZYCodeunit.ReadInternalFieldInEmailOutbox();
    end;
}

codeunit 50116 ZYCodeunit
{
    Permissions = tabledata "Email Outbox" = r;

    procedure ReadInternalFieldInEmailOutbox()
    var
        RecRef: RecordRef;
        FldRef: FieldRef;
    begin
        RecRef.Open(Database::"Email Outbox");
        FldRef := RecRef.Field(1); // Field Id 
        FldRef.SetRange(3);
        FldRef := RecRef.Field(2);//Field Message Id
        if RecRef.FindFirst() then
            Message(Format(FldRef.Value));
    end;
}

As for the internal table, first of all we cannot set the Permission Property for it.

And, Database::”User Login” cannot be used in RecordRef.Open method, only the table number can be used.

But still the same error in Permission Property.

So, even if there is no problem with our code, it will prompt insufficient permissions when running.

These are the results of my tests, I hope they can give you some help. Give it a try!!!😁

PS:
1. Even if you have Super permission, or you have added permissions to the Permission Set, you cannot access the internal table.

2. Extensions with internalsVisibleTo set in the App.json file can access internal tables. But since we cannot modify the app.json file of the standard extension, this method can only be used in our custom extensions.

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL