Use SetAutoCalcFields when each iterated row needs a FlowField
Record.SetAutoCalcFields has been available since runtime 1.0 and makes the specified FlowFields calculate as records are retrieved. Microsoft's AL database-method performance guidance uses it to remove an explicit CalcFields call from every iteration when each row's FlowField drives a branch.
- microsoftlayer
- performancedomain
- 2examples
- 3pull requests
Rule on GitHub · microsoft layer · performance · BC all · tier official · derived
Description
Record.SetAutoCalcFields has been available since runtime 1.0 and makes the specified FlowFields calculate as records are retrieved. Microsoft’s AL database-method performance guidance uses it to remove an explicit CalcFields call from every iteration when each row’s FlowField drives a branch. This is different from CalcSums, which returns a total for the filtered set rather than a value for each row.
Best Practice
Call SetAutoCalcFields before FindSet when every returned row needs the same FlowField for a comparison, branch, or per-record action. For one total of a stored source field, consider CalcSums instead (see stored-field totals versus FlowFields). If the required result is a total of selected FlowField values, derive the underlying source filters from CalcFormula; do not sum the FlowField directly with CalcSums.
See sample: use-setautocalcfields-for-per-row-flowfields.good.al.
Anti Pattern
Calling CalcFields inside the loop when every iteration reads the same FlowField. A compatible recent result can be cached, so do not equate each call with a SQL statement. Do not replace row-specific decisions with CalcSums; an aggregate cannot preserve which rows met the condition.
See sample: use-setautocalcfields-for-per-row-flowfields.bad.al.
Examples
- Good: use-setautocalcfields-for-per-row-flowfields.good.al
- Bad: use-setautocalcfields-for-per-row-flowfields.bad.al
Names
- Record.CalcFields(Any [, Any,…]) Method (names CalcFields)
- Record.CalcSums(Any [, Any,…]) Method (names CalcSums)
Changed by
- #198 Add BC performance knowledge from OptimAL learnings, 2026-09-29
- #174 Make BCQuality documentation easier for partners to get started, 2026-09-09
- #97 Add per-row AL performance guidance, 2026-07-14
From microsoft/BCQuality at a4593a1, MIT License, Copyright (c) 2026 Microsoft Corporation (license).