community postAL Developmentcommunity - not Microsoftreviewed - checked by Opus

Quick Tip: CalcFields vs SetAutoCalcFields in AL

FlowFields in Business Central are not stored in the database and must be calculated explicitly. The post explains two methods for calculating them: CalcFields for one-time calculations on single records, and SetAutoCalcFields for automatic calculation during record retrieval, with guidance on which to use to avoid performance issues.

post think about IT

Steven Renders · 2026-04-23 · 502 words · about 2 min

"Inside a loop, calling CalcFields on every iteration means a separate database call per record."

Key points

  • CalcFields explicitly calculates FlowFields on the current record when called and is suitable for single-record calculations outside loops
  • SetAutoCalcFields automatically calculates specified FlowFields for every record retrieved during FindSet or loop iterations, improving performance over repeated CalcFields calls
  • Calling SetAutoCalcFields without parameters clears the auto-calculation list for the record variable
  • SetAutoCalcFields is scoped to the record variable, not the table, so different variables do not inherit the setting
  • As of BC26 (AL runtime 15.0), SetAutoCalcFields is available on RecordRef, enabling generic code to use the same pattern

Quotes

  • “Inside a loop, calling CalcFields on every iteration means a separate database call per record.” (Explains the key performance problem that SetAutoCalcFields solves)
  • “Use SetAutoCalcFields before any loop where you need a FlowField on every record.” (Provides the main guideline for correct usage to achieve optimal performance)

Context

  • Features: CalcFields method, SetAutoCalcFields method, FlowField calculation, RecordRef support
  • Versions: BC26, 2025 release wave 1, AL runtime 15.0

Source: think about IT - Steven Renders, community blog. Summary, key points and quotes are derived (CONTENT-NOTICE.md); read the original for the full text.