Dynamics 365 Business Central: Matters needing attention when creating a new setup page

Dynamics 365 Business Central

Hi, Readers.
Today I would like to share some matters needing attention when creating a new setup page in Business Central.

As you might have known, when we customize a new function, it is recommended to add a switch option for the new feature just like standard. For example, use the boolean field and other settings fields.
Inventory Setup in Business Central:

This is not only to facilitate enabling and disabling new features at any time but also to try to avoid affecting standard features.

So when we create a new setup page, what should we pay attention to?

1. Primary Key(Code 10): Blank
The primary key of the setup table should be Code[10]. And do not display the primary key on the page.

2. PageType of the setup page: Card

    PageType = Card;

3. Setting Page Permissions (InsertAllowed and DeleteAllowed)
Generally, there is only one record in the setup table, so users are not allowed to delete and add new settings.

page 50113 "ZY Setup"
{
    PageType = Card;
    Caption = 'ZY Setup';
    ApplicationArea = All;
    UsageCategory = Administration;
    SourceTable = "ZY Setup";
    InsertAllowed = false;
    DeleteAllowed = false;
}

4. OnOpenPage() trigger
When opening the page for the first time, a empty record is automatically inserted.

    trigger OnOpenPage()
    begin
        Rec.Reset;
        if not Rec.Get() then begin
            Rec.Init();
            Rec.Insert();
        end;
    end;

So far, a basic setup page has been created.
Test Video:

Source Code:
Table:

table 50112 "ZY Setup"
{
    Caption = 'ZY Setup';

    fields
    {
        field(1; "Primary Key"; Code[10])
        {
            Caption = 'Primary Key';
            DataClassification = CustomerContent;
        }
        field(2; "Test Setup Field"; Boolean)
        {
            Caption = 'Test Setup Field';
            DataClassification = CustomerContent;
        }

    }

    keys
    {
        key(PK; "Primary Key")
        {
            Clustered = true;
        }
    }
}

Page:

page 50113 "ZY Setup"
{
    PageType = Card;
    Caption = 'ZY Setup';
    ApplicationArea = All;
    UsageCategory = Administration;
    SourceTable = "ZY Setup";
    InsertAllowed = false;
    DeleteAllowed = false;


    layout
    {
        area(Content)
        {
            group(GroupName)
            {
                Caption = 'General';
                field("Test Setup Field"; Rec."Test Setup Field")
                {
                    ApplicationArea = All;
                }
            }
        }
    }

    trigger OnOpenPage()
    begin
        Rec.Reset;
        if not Rec.Get() then begin
            Rec.Init();
            Rec.Insert();
        end;
    end;
}

Remark01. You can add new settings fields to the existing settings page
For example: Sales -> Sales & Receivables Setup

TableExtension:

PageExtension:

Sales & Receivables Setup page:

Remark02. Add new settings about users.
Because the User (2000000120) table is a system table, you cannot expand it.

For example:

So if you want to expand user settings, please try to expand User Setup (91) table and User Setup (119, List) page.

TableExtension:

PageExtension:

User Setup page:

Remark03. Create a Wizard and Assisted Setup
Wizard is a step by step guidance through a setup process, and Assisted Setup is a list of setup scenarios to help Business Central User setting up a module. So In order to facilitate user settings, you should consider creating one or more Assisted Setups for your extension when creating an extension for Business Central.
For Details: How to create a Wizard (NavigatePage) and Assisted Setup

Wizard Page:

Assisted Setup:

Update
Remark04. GetRecordOnce function

Extra Tip from Arend-Jan Kauffmann.

For Example:
How to define:
In table 311 “Sales & Receivables Setup”

In table 98 “General Ledger Setup”

How to use:
In codeunit 57 “Document Totals”:

In codeunit 12 “Gen. Jnl.-Post Line”:

END

Hope this will help.

Thanks for reading.

ZHU

コメント

タイトルとURLをコピーしました