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

Reopening a Query resets its cursor but keeps its filters

Calling Open() on an already open query first closes the current dataset and opens it again. The next Read() starts at the first row; it does not continue from the previous cursor. Reopening also retains filters previously applied to the query variable.

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

Description

Calling Open() on an already open query first closes the current dataset and opens it again. The next Read() starts at the first row; it does not continue from the previous cursor. Reopening also retains filters previously applied to the query variable. Only Clear(QueryVariable) resets those filters, so reuse can unexpectedly reread the first row or carry an old filter into a logically separate operation.

Best Practice

Open once for one read pass. Close after the pass, and call Clear(QueryVariable) before reusing the variable for a logically independent query whose filters must start empty. Set the next pass’s filters explicitly before reopening.

See sample: reopening-query-resets-cursor-but-keeps-filters.good.al.

Anti Pattern

Calling Open() inside or between reads to “advance” or “start fresh”, or reusing the same query variable for a new operation while assuming Open() cleared old filters. The code compiles but can repeatedly process the first row or silently omit rows behind a retained filter.

See sample: reopening-query-resets-cursor-but-keeps-filters.bad.al.

Examples

Changed by


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