Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / AL

Designing an Extension in Dynamics 365 Business Central using AL Language Plugin within Visual Studio Code

0.00/5 (No votes)
8 Dec 2023CPOL2 min read 2.7K   16  
Dynamic utility for viewing and browsing schema info and data runtime
The Schema Design Viewer utility in Dynamics 365 Business Central enables real-time access to table structure information and data browsing, and offers a quick-reference tool without relying on development environments. Leveraging AL language in Visual Studio Code, it supports object schema and data cross-checking, facilitating efficient schema access and runtime data validation. This utility aids in the migration process by simultaneously validating object designs and data, with potential enhancements planned for future releases.

Introduction

Schema Design Viewer utility within Dynamics 365 Business Central is designed to provide basic table design and structure information, which also lets users browse the data from the desired tables at runtime.

Background

V2 Extensions using AL language in Visual Studio Code is designed within Microsoft Dynamics 365 Business Central. This article is intended to target audiences who are intermediate and advanced users familiar with AL language, Visual Studio Code and Dynamics 365 Business Central ERP.

This extension was designed to cross check the schemas and data from the objects at runtime without leaning on the development tools/environment. This provides a quick reference and access to all objects (including Custom + Out of the box Schemas) in Dynamics 365 Business Central ERP.

For more detailed information on the Dynamics 365 Business Central ERP features, please visit this link.

Using the Code

Here's a quick tour in designing V2 Extensions using AL language in Visual Studio Code with Microsoft Dynamics 365 Business Central. This extension assists in viewing the schema structure and lets user browse data in separate tabs in browser.

Following extension is dependent on Microsoft System Application and Microsoft Base Application out of the box extensions, used are v17.1 base app references for development and tested it in version BC 18.3.

Deploy the attached extension app file from the zip using the following command from the Administration Business Central Development Shell.

Image 1

Publish-NAVApp -ServerInstance BC180 
-Path ".\Chaitanya Kanumukula_Schema Design Viewer_1.0.0.0.app" -SkipVerification 

Visual Studio Code - Development IDE

Below is a demonstration of the image for reference to show the reference packages used in the build process, This compiled app supports BC version starting from v17.1 onwards to the latest.

Image 2

If you would like to compile the app with previous versions of BC, then please download the source and use the older references of the above mentioned packages to target/deploy on an older Dynamics 365 Business Central version.

C#
/// <summary>
/// Page Schema Design Viewer And Browser (ID 50140).
/// Utility designed for unblocking users from accessing 
/// the basic table design information and browse data of the table object.
/// Need this extension specially at the runtime.
/// </summary>
///
page 50140 "Schema Design Viewer"
{
    PageType = list;
    ApplicationArea = All;
    UsageCategory = Lists;
    SourceTable = Field;

    /// <summary>
    /// Field is a SYSTEM table of 2000000041
    /// BC out of the box doens't allow the delete, Modify, 
    /// Insert options on Table design and Structures.
    /// </summary>
    DeleteAllowed = false;
    InsertAllowed = false;

   layout
    {
        area(Content)
        {
            group(General)
            {
                field("Table ID"; "Table ID")
                {
                    ApplicationArea = All;
                    ToolTip = 'Table ID';
                    Caption = 'Table ID';
                    Lookup = true;
                    TableRelation = "Table Metadata".ID;

                    // After selection when the focus of the control moves to next
                    // Change the Object link.
                    trigger OnValidate()
                    begin
                        ObjectURLLink := DrillDownURLTxt + FORMAT("Table ID");
                    end;
                }

                field("ObjectURL"; "ObjectURLLink")
                {
                    ApplicationArea = All;
                    Editable = true;
                    ToolTip = 'Browse Object URL';
                    Caption = 'Browse Object URL';

                    // Create the link to the database schema object, 
                    // so it can be opened in a separate tabs in browser.
                    // This will be handy, if it can be opened in separate tabs.
                    trigger OnDrillDown()              
                    begin

                        ObjectURLLink := DrillDownURLTxt + FORMAT("Table ID");
                        Hyperlink(DrillDownURLTxt + FORMAT("Table ID"));
                    end;
                }
            }
            repeater(GroupName)
            {
                field(TableNo; rec.TableNo)
                {
                    ApplicationArea = All;
                    Editable = false;
                    ToolTip = 'TableNo';
                    Caption = 'TableNo';
                }
                field("No."; rec."No.")
                {
                    ApplicationArea = all;
                    Editable = false;
                    ToolTip = 'No';
                    Caption = 'No';
                }
                field(TableName; rec.TableName)
                {
                    ApplicationArea = all;
                    Editable = false;
                    ToolTip = 'TableName';
                    Caption = 'TableName';
                }
                field(FieldName; rec.FieldName)
                {
                    ApplicationArea = all;
                    Editable = false;
                    ToolTip = 'FieldName';
                    Caption = 'FieldName';
                }
                field("Type Name"; rec."Type Name")
                {
                    ApplicationArea = all;
                    Editable = false;
                    ToolTip = 'Type Name';
                    Caption = 'Type Name';
                }
                field(Len; rec.Len)
                {
                    ApplicationArea = all;
                    Editable = false;
                    ToolTip = 'Len';
                    Caption = 'Len';
                }
                field(OptionString; rec.OptionString)
                {
                    ApplicationArea = all;
                    Editable = false;
                    ToolTip = 'OptionString';
                    Caption = 'OptionString';
                }
                field(RelationTableNo; rec.RelationTableNo)
                {
                    ApplicationArea = all;
                    Editable = false;
                    ToolTip = 'RelationTableNo';
                    Caption = 'RelationTableNo';
                }
                field(RelationFieldNo; rec.RelationFieldNo)
                {
                    ApplicationArea = all;
                    Editable = false;
                    ToolTip = 'RelationFieldNo';
                    Caption = 'RelationFieldNo';
                }
            }
        }
        area(Factboxes)
        {
        }
    }
    actions
    {
        area(Processing)
        {
            action(ActionName)
            {
                ApplicationArea = All;
                Caption = 'Show Table Details';
                ToolTip = 'Show Table Details';
                Image = ShowSelected;
                Promoted = true;
                PromotedOnly = true;
                PromotedCategory = Process;

                trigger OnAction();
                begin
                    rec.SetRange(TableNo, "Table ID");
                end;
            }

            action(ActionName1)
            {
                ApplicationArea = All;
                Caption = 'Browse Data';
                ToolTip = 'Browse Data';
                Image = ShowSelected;
                Promoted = true;
                PromotedOnly = true;
                PromotedCategory = Process;
                trigger OnAction();
                begin
                    rec.SetRange(TableNo, "Table ID");
                    Hyperlink(DrillDownURLTxt + FORMAT("Table ID"));
                end;
            }
       }
    }
    trigger OnOpenPage()
    var
    begin
        DrillDownURLTxt := GetUrl(ClientType::Web) + '/?table=';
    end;

    // Prompt message on modification                  
    trigger OnModifyRecord(): Boolean
    begin
        Error('Modification is not allowed on the schema structures.');
    end;
    var
        "Table ID": Integer;
        DrillDownURLTxt: Text;
        ObjectURLLink: Text;
}

Using the Extension

Install the Schema Design Viewer extension in Dynamics 365 Business Central.

Image 3

Search the extension by its name and start using the below functionality.

  • User can click the "Show Table Details" from the top menu after typing the number in the TableID dropdown or by selecting the ID from the available full list.
  • Clicking on the "Browse Data" from the top menu or on the ellipse of "Browse Object URL" will open the table data in a new tabs on the browser.

Below is a demonstration highlighting the actions in real time.

Image 4

Points of Interest

Used this extension code practically while in the data migration process to cross check the object designs and data simultaneously. It assisted as a quick reference tool accessing the schema info and data during the runtime. I further wanted to add few more functionalities, but may enhance this later at some point in time with future releases.

History

  • 5th December, 2023: Initial release

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)