Do not hold locks while waiting for the user
A Confirm, StrMenu, or other user prompt issued from inside a write transaction stalls the transaction — and therefore every lock it holds — until the user responds.
- microsoftlayer
- performancedomain
- 2examples
- 2pull requests
Rule on GitHub · microsoft layer · performance · BC all · tier official · derived
Description
A Confirm, StrMenu, or other user prompt issued from inside a write transaction stalls the transaction — and therefore every lock it holds — until the user responds. Per the upstream guidance, “Avoid user interactions (Confirm, StrMenu) inside transactions — they hold locks while waiting for user input.” The wait is bounded only by the user; meanwhile other sessions block on whatever this transaction has acquired.
Best Practice
Sequence the operation so user confirmation happens before any database write that takes a lock the prompt holds open. The shape is: ask the user → if confirmed, acquire locks and post. if Confirm(...) then begin SalesHeader.LockTable(); SalesHeader.Get(DocNo); PostSalesOrder(SalesHeader); end; keeps the lock window down to the work itself.
See sample: avoid-user-prompts-inside-transactions.good.al.
Anti Pattern
SalesHeader.LockTable(); SalesHeader.Get(DocNo); if Confirm('Post this order?') then ...; — the lock is held for as long as the dialog is up. A user who steps away to lunch holds the lock for an hour, and every other session that touches that row blocks for the duration.
See sample: avoid-user-prompts-inside-transactions.bad.al.
Examples
- Good: avoid-user-prompts-inside-transactions.good.al
- Bad: avoid-user-prompts-inside-transactions.bad.al
Names
- Dialog.StrMenu(Text [, Integer] [, Text]) Method (names StrMenu)
Changed by
- #161 AL methods limited during write transactions (RunModal, Codeunit.Run), 2026-09-29
- #174 Make BCQuality documentation easier for partners to get started, 2026-09-09
From microsoft/BCQuality at a4593a1, MIT License, Copyright (c) 2026 Microsoft Corporation (license).