mirror of
https://github.com/microsoft/BCQuality.git
synced 2026-10-05 14:46:55 +01:00
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>
18 lines
715 B
AL
18 lines
715 B
AL
codeunit 50259 "Perf Sample RunModalInTxn Good"
|
|
{
|
|
procedure ChangeShippingAgent(DocNo: Code[20])
|
|
var
|
|
SalesHeader: Record "Sales Header";
|
|
ShippingAgent: Record "Shipping Agent";
|
|
begin
|
|
// User interaction first, while no write transaction is open.
|
|
if Page.RunModal(Page::"Shipping Agents", ShippingAgent) <> Action::LookupOK then
|
|
exit;
|
|
|
|
// All writes after the choice is made; the transaction ends with the trigger.
|
|
SalesHeader.Get(SalesHeader."Document Type"::Order, DocNo);
|
|
SalesHeader."Shipment Date" := WorkDate();
|
|
SalesHeader.Validate("Shipping Agent Code", ShippingAgent.Code);
|
|
SalesHeader.Modify(true);
|
|
end;
|
|
}
|