Skip to content
Arthur edited this page Mar 12, 2024 · 7 revisions

Utilize the Page Management codeunit for launching page.

The idea behind this rule is to raise awareness that there is the option of utilizing the Page Management codeunit rather than invoking Page.Run(0, ...) directly.

The benefits:

  • Automatically determine the appropriate page to run (Sales Order vs. Sales Quote vs. ...).
  • Automatically an extra check for IsGuiAllowed()
  • Automatically converts the 'Rec-Related' Variant to a RecordRef
  • OnAfterGetPageID event publisher for extensions (and other similar event publishers)

Source: https://github.com/StefanMaron/MSDyn365BC.Code.History/blob/master/BaseApp/Source/Base%20Application/Utilities/PageManagement.Codeunit.al

Example

Calling the Page.Run() function directly

local procedure OpenPage()
var
    SalesHeader: Record "Sales Header";
begin
    Page.Run(Page::"Sales Quote", SalesHeader);
end;

Calling the Page.Run() function through the Page Management codeunit

local procedure OpenPage()
var
    SalesHeader: Record "Sales Header";
    PageManagement: Codeunit "Page Management";
begin
    PageManagement.PageRun(SalesHeader);
end;

Card vs List page

The Page Management codeunit is intended for Card pages and Worksheet for journals.
You can utilize the Page Management code also for List pages with the following approach

local procedure OpenPage()
var
    SalesHeader: Record "Sales Header";
    PageManagement: Codeunit "Page Management";
begin
    if SalesHeader.Count() = 1 then
        PageManagement.PageRun(SalesHeader)
    else
        Page.Run(PageManagement.GetDefaultLookupPageIDByVar(SalesHeader), SalesHeader);
end;

Supported tables

This rule wil also be raised when one the tables below is passed as a record variable.

Id Name
36 Sales Header
38 Purchase Header
79 Company Information
80 Gen. Journal Template
81 Gen. Journal Line
91 User Setup
98 General Ledger Setup
112 Sales Invoice Header
131 Incoming Documents Setup
207 Res. Journal Line
210 Job Journal Line
232 Gen. Journal Batch
312 Purchases & Payables Setup
454 Approval Entry
843 Cash Flow Setup
1251 Text-to-Account Mapping
1275 Doc. Exch. Service Setup
5107 Sales Header Archive
5109 Purchase Header Archive
5200 Employee
5405 Production Order
5900 Service Header
5965 Service Contract Header
7152 Item Analysis View
2000000120 User

Exceptions

There are some exceptions where calling directly the Page.Run() make sense.

Absence of a record context

Page.Run(Page::"Customer Card");

Using the return Action

local procedure SelectCustomer()
var
    CustomerRec: Record Customer;
begin
    if Page.RunModal(Page::"Customer Lookup", CustomerRec) = Action::LookupOK then
        DoStuffWithSelectedCustomer(CustomerRec);
end;

Declaring the page as variable

local procedure SelectCustomer()
var
    CustomerRec: Record Customer;
    CustomerCard: Page "Customer Card";
begin
    CustomerCard.SetRecord(CustomerRec);
    CustomerCard.Run();
end;