BCQuality rule · uiAL Developmentofficial - Microsoftderived - from the source, no model text

Open documents from a mixed-type list through Page Management

Some tables back several document pages, chosen by a type field. Sales Header rows open as Sales Quote, Sales Order, Sales Invoice, Sales Credit Memo, Blanket Sales Order, or Sales Return Order, depending on Document Type. A list over such a table cannot use one CardPageID.

Rule on GitHub · microsoft layer · ui · BC all · tier official · derived

Description

Some tables back several document pages, chosen by a type field. Sales Header rows open as Sales Quote, Sales Order, Sales Invoice, Sales Credit Memo, Blanket Sales Order, or Sales Return Order, depending on Document Type. A list over such a table cannot use one CardPageID. Codeunit 700 "Page Management" already holds that mapping. PageRun(Rec) resolves the page through GetPageID, in this order: GetConditionalCardPageID, then the default card page (only for an existing record), then GetConditionalListPageID, then the table’s lookup page. GetConditionalCardPageID handles Sales Header, Purchase Header, their archives, general and item journal batches and lines, requisition worksheets, and several other tables. Base App’s own lists call it: the Show Document actions on Sales List and Purchase List, Sales Lines (after getting the header), and Navigate for posted documents.

A hand-written case Rec."Document Type" of ... Page.Run(Page::"Sales Order", Rec) copies that mapping into a single action. It misses mappings that Microsoft later adds to Page Management, and routing that extensions add through its events (OnBeforeGetConditionalCardPageID, OnAfterGetPageID, OnPageRunAtFieldOnBeforeRunPage). Page Management does not route new values of an extended Sales Document Type enum by itself either, so those still need a subscriber.

Best Practice

In the list’s open-document action, call PageManagement.PageRun(Rec), or PageRunModal or PageRunList as needed. PageRun returns false without opening anything when GuiAllowed is false or no page resolves. See sample: list-page-document-routing-uses-page-management.good.al.

For a new table whose rows map to different pages, register the mapping once and then use PageRun everywhere. Subscribe to OnConditionalCardPageIDNotFound, which is raised only for tables the codeunit does not route itself. Microsoft’s Sustainability app routes its journal batch and line tables this way. OnBeforeGetConditionalCardPageID is the IsHandled alternative, used by the Quality Management app.

Anti Pattern

A page action that opens a record of a table Page Management routes, directly or after a Get, by switching on its Document Type (or a similar type field) and calling Page.Run(Page::...) in each branch. Base App still does this in several places, for example the Show Document actions of Sales Line Archive List and Purchase Line Archive List, and Copy Document Mgt. ShowSalesDoc/ShowPurchDoc. The result is a duplicated mapping, not a runtime error, so report it as minor. The same switch in a codeunit helper is outside this review’s page scope. See sample: list-page-document-routing-uses-page-management.bad.al.

Not this pattern:

  • Opening one known document type directly. Opportunity creates a quote and runs Sales Quote, and a single-type list such as Sales Order List sets CardPageID = "Sales Order".
  • A table that Page Management does not route. Assembly List switches on Assembly Header."Document Type" itself. Registering the table through OnConditionalCardPageIDNotFound is an improvement there, not a defect fix.

References

Examples

Names

Changed by


From microsoft/BCQuality at a4593a1, MIT License, Copyright (c) 2026 Microsoft Corporation (license).