pageextension 50100 "Purchase Order" extends "Purchase Order"
{
DataCaptionExpression = TextVar;
layout
{
modify("No.")
{
Visible = ShowPurchOrderNo;
}
}
trigger OnAfterGetCurrRecord()
begin
SetControls();
end;
trigger OnAfterGetRecord()
begin
SetControls();
end;
trigger OnOpenPage()
begin
SetControls();
end;
local procedure SetControls()
var
Setup: Record Setup;
begin
ShowPurchOrderNo := true;
TextVar := Rec."No." + ' - ' + Rec."Buy-from Vendor Name";
if Setup.Get() then
if Setup."Hide Purchase Order No." then
if Rec.Status <> Rec.Status::Released then begin
ShowPurchOrderNo := false;
TextVar := Rec."Buy-from Vendor Name";
end;
end;
var
ShowPurchOrderNo: Boolean;
TextVar: Text[2048];
}
EXPECTED RESULT
The No. field should hide, since ShowPurchOrderNo recalculates to false for the Open record in OnAfterGetCurrRecord.
ACTUAL RESULT
The No. field remains visible, retaining the state from when the page was first opened. It does not update on navigation.
WHAT WE ALREADY VERIFIED
1. The boolean recalculates correctly every time - confirmed via DataCaptionExpression updating correctly on every Next/Previous click.
2. Tried CurrPage.Update(false) after recalculating in OnAfterGetCurrRecord - no change.
3. For comparison, native page elements defined directly in the base page (e.g. the WorkflowStatus FactBox part, bound to ShowWorkflowStatus and recalculated in OnAfterGetCurrRecord with no CurrPage.Update call) DO correctly toggle visibility per record during navigation. This suggests a difference between extension-modified existing fields and natively-defined page elements.
4. A JavaScript Control AddIn workaround (DOM manipulation, MutationObserver, CSS injection) works but is fragile and fights the client re-render cycle - not a sustainable solution for what should be basic AL functionality.
5. Also tried subscribing to the standard integration event OnBeforePurchaseDocumentNoIsVisible in codeunit 1400 DocumentNoVisibility (the event that controls the native DocNoVisible variable bound to the No. field on the base Purchase Order page). This event only fires once, from OnOpenPage via SetDocNoVisible -> SetOpenPage, and is never re-evaluated on Next/Previous navigation - so subscribing to it does not solve the per-record dynamic visibility requirement either. It only affects whichever record happens to be loaded first when the page opens.
[EventSubscriber(ObjectType::Codeunit, Codeunit::DocumentNoVisibility, 'OnBeforePurchaseDocumentNoIsVisible', '', false, false)]
local procedure OnBeforePurchaseDocumentNoIsVisible(DocType: Option; DocNo: Code[20]; var IsVisible: Boolean; var IsHandled: Boolean)
var
Setup: Record Setup;
PurchHeader: Record "Purchase Header";
begin
if DocType <> 1 then // 1 = Order
exit;
if not Setup.Get() then
exit;
if not Setup."Hide Purchase Order No." then
exit;
IsHandled := true;
if DocNo = '' then begin
IsVisible := true;
exit;
end;
if PurchHeader.Get(PurchHeader."Document Type"::Order, DocNo) then
IsVisible := PurchHeader.Status = PurchHeader.Status::Released
else
IsVisible := true;
end;
QUESTIONS
1. Is this a known/by-design limitation of the Visible property when set via modify() on an existing base-page field inside a page extension, specifically for re-evaluation during Next/Previous navigation?
2. Is there a supported pattern for per-record dynamic field visibility in a page extension that updates correctly during navigation without a full page reload (Page.Run)?
3. Does adding the dynamic Visible binding to a newly added field (via addafter/addbefore) instead of modifying an existing field make a behavioral difference? Is this documented anywhere?
Any guidance or confirmation of a platform limitation would be appreciated. Happy to share the full extension source if useful for reproduction.