bcquality/microsoft/knowledge/performance/use-setautocalcfields-for-per-row-flowfields.md
Jesper Schulz-Wedde 2b5550c346
Some checks failed
Validate knowledge index / validate-index (push) Has been cancelled
Validate AL review fixtures / validate-review-fixtures (push) Has been cancelled
Validate frontmatter and structure / validate (push) Has been cancelled
Improve partner onboarding and documentation navigation (#174)
Lead with a complete plugin quick start and add task-oriented usage, troubleshooting, customization, and contribution guides. Preserve the broader plugin framing, correct conflicting contract guidance, support Agents folder reviews, and align repository validation. Convert existing sample references to clickable links without changing knowledge rules.

Co-authored-by: Jesper Schulz-Wedde <jesper.schulzwedde@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
2026-09-09 17:31:03 +02:00

1.7 KiB

bc-version domain keywords technologies countries application-area
all
performance
setautocalcfields
calcfields
calcsums
flowfield
loop
per-row
al
w1
all

Use SetAutoCalcFields when each iterated row needs a FlowField

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. Use CalcSums instead when the required result is one aggregate over the filtered set (see calcsums-instead-of-calcfields-in-loop.md).

See sample: use-setautocalcfields-for-per-row-flowfields.good.al.

Anti Pattern

Calling CalcFields inside the loop when every iteration reads the same FlowField. Each CalcFields request requires a separate SQL statement unless a compatible recent result is cached. 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.