bcquality/microsoft/knowledge/performance/runmodal-is-not-allowed-inside-write-transactions.bad.al
Michael Dieringer 2a4cb856ef Add runmodal-is-not-allowed-inside-write-transactions.md; drop "modal page" from the prompts article
A modal page does not behave like Confirm/StrMenu inside a write
transaction: the platform refuses Page.RunModal (and Report/XmlPort
.RunModal with a request page, and Codeunit.Run with its return value
used) with a runtime error instead of holding the lock. The new article
documents that guard - verified against Microsoft Learn (Codeunit.Run
transaction semantics), microsoft/AL#5452, Microsoft's own Base
Application (Commit(); Page.RunModal pattern), and a live reproduction
on Business Central 26 quoted verbatim. avoid-user-prompts-inside-
transactions.md keeps its scope to the prompts the platform does allow;
"modal page" is removed from its list because that case is refused, not
stalled.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-21 21:56:30 +02:00

18 lines
706 B
AL

codeunit 50258 "Perf Sample RunModalInTxn Bad"
{
procedure ChangeShippingAgent(DocNo: Code[20])
var
SalesHeader: Record "Sales Header";
ShippingAgent: Record "Shipping Agent";
begin
SalesHeader.Get(SalesHeader."Document Type"::Order, DocNo);
SalesHeader."Shipment Date" := WorkDate();
SalesHeader.Modify(true); // a write transaction is now open
// Runtime error: RunModal is not allowed in write transactions.
if Page.RunModal(Page::"Shipping Agents", ShippingAgent) = Action::LookupOK then begin
SalesHeader.Validate("Shipping Agent Code", ShippingAgent.Code);
SalesHeader.Modify(true);
end;
end;
}