Dynamics 365 Business Central: How to get object name from object id and type via AL

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about a simple topic, how to get object name from object id and type via AL.
I recently saw a simple question:

If I know the ID of the XmlPort, how can I know its name as text in a local procedure?

https://forum.mibuso.com/discussion/78278/if-i-know-the-id-of-the-xmlport-how-can-i-know-its-name-as-text-in-a-local-procedure

For example, what is the name of XmlPort 11?

Regarding getting object information about the currently opened page, we have previously discussed the following content:

This time it’s not difficult either, we can just use table 2000000038 AllObj or table 2000000058 AllObjWithCaption.
table 2000000038 AllObj:

table 2000000058 AllObjWithCaption: We used this table when discussing Dynamics 365 Business Central: View the all object details (Type, ID, Name…) and find out what extension an object belong to without using VS Code

So it’s very simple,

Test code:

pageextension 50119 CustomerListExt extends "Customer List"
{
    trigger OnOpenPage()
    var
        AllObjWithCaption: Record AllObjWithCaption;
    begin
        if AllObjWithCaption.Get(ObjectType::XmlPort, 11) then
            Message('Object ID: %1, Object Type: %2\Object Name is ''%3''', AllObjWithCaption."Object ID", AllObjWithCaption."Object Type", AllObjWithCaption."Object Name");
    end;
}

Let me discuss this further. I created a simple tool.
PS:
1. Dynamics 365 Business Central: How to add a request/filter page for the list page (FilterPageBuilder Data Type)
2. Dynamics 365 Business Central: OnAction trigger on Role Center pages (Error: A page of type Role Center cannot have triggers)

A simple test:

Great.

Test video:

Very simple, give it a try!!!😁

Source Code: GitHub (Please note that the source code is for reference only, you can improve it according to your own needs)

pageextension 50116 BusinessManagerRCExt extends "Business Manager Role Center"
{
    actions
    {
        addafter("Sales Order")
        {
            action("Get Object Info")
            {
                Caption = 'Get Object Info';
                ApplicationArea = All;
                RunObject = codeunit GetObjectInfo;
            }
        }
    }
}

codeunit 50119 GetObjectInfo
{
    trigger OnRun()
    var
        varFilterPageBuilder: FilterPageBuilder;
        AllObjWithCaption: Record AllObjWithCaption;
    begin
        varFilterPageBuilder.AddTable('All Objects with caption', AllObjWithCaption.RecordId.TableNo);
        varFilterPageBuilder.AddFieldNo('All Objects with caption', AllObjWithCaption.FieldNo("Object ID"));
        varFilterPageBuilder.AddFieldNo('All Objects with caption', AllObjWithCaption.FieldNo("Object Type"));
        varFilterPageBuilder.PageCaption := 'All Objects with caption Filter Page';
        if varFilterPageBuilder.RunModal() then begin
            AllObjWithCaption.SetView(varFilterPageBuilder.GetView('All Objects with caption'));
            if AllObjWithCaption.FindFirst() then
                Message('Object ID: %1, Object Type: %2\Object Name is ''%3''', AllObjWithCaption."Object ID", AllObjWithCaption."Object Type", AllObjWithCaption."Object Name");
        end;
    end;
}

PS:
1. Dynamics 365 Business Central: System tables, Virtual tables and Virtual tables (entities) in Dataverse

2. Dynamics 365 Business Central: Viewing table data (Six ways)

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL