---
id: guideline/microsoft/skills/review/al-query-review
type: guideline
title: AL Query review
summary: Reviews AL Query objects and Query instance usage against BCQuality guidance.
tier: official
language: en
tags:
  - review-skill
system: development
review:
  state: derived
  by: null
  at: null
  flags: []
generated:
  at: "2026-10-29T21:27:25.990Z"
  pipeline: 0.2.0
  prompts: {}
  input_hash: 018cadc3f3e1176b74391da2a1632fb31a3f2859
evidence:
  - kind: guideline
    url: https://github.com/microsoft/BCQuality/blob/main/microsoft/skills/review/al-query-review.md
    title: "microsoft/BCQuality: AL Query review"
    date: "2026-10-20"
    commit: a4593a1b1585a0fa663efbf39ff02c60f846d851
    t: null
    quote: null
links:
  learn: []
  objects: []
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
  changes:
    - change/bcquality/230
    - change/bcquality/186
    - change/bcquality/179
    - change/bcquality/172
    - change/bcquality/108
repo_path: microsoft/skills/review/al-query-review.md
layer: microsoft
kind: skill
domain: null
bc_version:
  - all
technologies:
  - al
countries:
  - w1
application_area:
  - all
examples: 0
identifiers:
  - QueryType
  - DataItemLink
  - SqlJoinType
  - InnerJoin
  - LeftOuterJoin
  - SetFilter
  - SetRange
  - DataItemTableFilter
  - ColumnFilter
---

# AL Query review

> Reviews AL Query objects and Query instance usage against BCQuality guidance.

[Skill on GitHub](https://github.com/microsoft/BCQuality/blob/main/microsoft/skills/review/al-query-review.md) · microsoft layer · review skill · BC all · tier official · derived

Reviews AL source changes against the `query` knowledge domain in BCQuality. This is a leaf action skill composed by `al-code-review`.

## Source

Use READ's **Bounded retrieval for review skills** workflow with `-Domain query`. Consume every catalog page across enabled layers before applying this leaf's Relevance and Worklist; preserve each exact catalog path and open complete bodies only for exact paths selected by the Worklist. If the helper or prepared index is unavailable or invalid, use READ's explicit path-discovery and bounded native-read fallback.

## Relevance

Apply READ's frontmatter matching rules against the task context. Use the target version from `app.json` when available and `[al]` for technologies. Retain conditionally applicable files only when configured; cap resulting confidence at `medium` and name every unknown dimension in the finding message.

Return `not-applicable` when the input contains no Query object declaration and no Query variable method call.

## Worklist

Match relevant entries against changed `query` objects, variables typed as `Query`, and the tokens `QueryType`, `dataitem`, `column`, `DataItemLink`, `SqlJoinType`, `InnerJoin`, `LeftOuterJoin`, `Method`, `Sum`, `Count`, `Average`, `Min`, `Max`, `SetFilter`, `SetRange`, `Open`, `Read`, `Close`, and `Clear`.

The following targeted checks cover every current `query` article:

- A `DataItemTableFilter` and a runtime `SetFilter` or `SetRange` constrain the same source field incompatibly, while the runtime call is intended to replace or broaden the static filter — `dataitemtablefilter-cannot-be-overwritten-at-runtime`.
- `SetFilter` or `SetRange` occurs after `Open()` without a new `Open()` before the next `Read()` — `set-query-filters-before-open`.
- A runtime `SetFilter` or `SetRange` replaces a `ColumnFilter` on the same column or filter row, while later code relies on the declarative restriction remaining effective — `setfilter-overwrites-query-columnfilter`.
- An already-open query is opened again as if that advanced the cursor, or a query variable is reused for an independent operation without `Clear` even though old filters must not carry over — `reopening-query-resets-cursor-but-keeps-filters`.
- A lower `dataitem` declares `DataItemLink` without `SqlJoinType`, unmatched rows survive the effective filters, and the consuming code incorrectly counts them as documents/entries or uses blank lower columns as matches — `query-dataitems-default-to-left-outer-join`. Require an observable row-selection defect, not a name or missing property alone. Do not match an explicit `LeftOuterJoin`, an implicit one whose consumer visibly expects unmatched rows, or null-rejecting child filters in the resulting SQL `WHERE` clause that already exclude unmatched rows (for example Sales Header `Document Type = Order` and `Status = Open`).
- A query with an aggregate `Method` (`Sum`, `Count`, `Average`, `Min`, `Max`) also declares a non-aggregated `column` whose value varies within the intended group (document, line, or entry number; a date without a date method), while the name or consuming code expects one row per group — `every-non-aggregated-query-column-is-a-group-key`.

Resolve layer conflicts per READ. When no query knowledge exists, emit `no-knowledge`; when knowledge exists but no article matches the changed Query usage, emit `completed` with no findings.

## Action

Evaluate every worklist article against the Query definition, the diff's call order, and surrounding control flow. For filter-precedence findings, require both the declarative filter and the runtime call to be visible, and require local evidence that replacement, broadening, or retention of the original filter is intended.

- Emit `major` for an unambiguous Anti Pattern that can close the dataset, restart processing, retain an unintended filter, produce an empty intersection, or admit rows excluded by an overwritten filter.
- Emit `minor` when code contradicts a Best Practice but the resulting behavior depends on unseen control flow.
- Do not emit applicability-only information. A Query article produces a finding only when the changed code violates its normative guidance.

Set confidence to `high` for a locally visible call sequence and `medium` when aliases, helper calls, or missing context obscure the sequence. Domain-scoped agent findings follow DO's precision bar and remain capped at `minor`/`medium`.

Provide `suggested-code` only when moving a filter before `Open()`, adding `Clear`, moving an invariant restriction to `DataItemTableFilter`, or composing the complete runtime filter is a complete, local, unambiguous replacement. Otherwise set `suggested-code-omission-reason`.

Outcome selection follows DO: `completed`, `no-knowledge`, `not-applicable`, `partial`, or `failed`.

## Output

Output conforms to the DO findings-report contract. Every finding this skill emits MUST set `findings[].domain` to `"Query"`.

## Changed by

- [#230 Knowledge: report layouts and dataset contract, query join and grouping defaults](../../../../changes/bcquality/230.md), 2026-10-20
- [#186 Add Query filter semantics guidance](../../../../changes/bcquality/186.md), 2026-09-15
- [#179 Add bounded knowledge retrieval](../../../../changes/bcquality/179.md), 2026-09-11
- [#172 Support standalone runners and complete app-folder reviews](../../../../changes/bcquality/172.md), 2026-09-09
- [#108 Complete AL review knowledge readiness](../../../../changes/bcquality/108.md), 2026-07-15

---

From microsoft/BCQuality at a4593a1, MIT License, Copyright (c) 2026 Microsoft Corporation ([license](../../../LICENSE-BCQuality.txt)).
