community postAL Developmentcommunity - not Microsoftreviewed - checked by Opus

Leveraging RecordRef and FieldRef for Dynamic Coding

This post explains how to use weakly typed RecordRef and FieldRef objects in Business Central AL for dynamic, flexible code when you don't know the record type at compile time. It contrasts weakly typed objects with strongly typed ones and demonstrates practical use cases like summing amounts across different table types and exporting any record set to Excel.

post Aardvark Labs

Marcel Chabot · 2026-03-06 · 1,499 words · about 7 min

"With all these advancements, why would we want to use a Weakly Typed object? Fantastic question hypothetical reader! In a word, flexibility."

Key points

  • Strongly typed objects provide compile-time validation, IntelliSense, safer refactoring, and better performance, while weakly typed objects offer flexibility for dynamic access to tables and fields
  • RecordRef and FieldRef are reference objects that provide the minimal common properties and procedures found in all strongly typed objects
  • RecordRef can be populated from a strongly typed record using GetTable(), and individual fields are accessed via FieldRef using either field ID or field index
  • Common use cases include logging, auditing, import frameworks, and generic code that works across multiple table structures without knowing the specific type

Quotes

  • “With all these advancements, why would we want to use a Weakly Typed object? Fantastic question hypothetical reader! In a word, flexibility.” (Identifies the core motivation for using weakly typed objects despite the strong benefits of strongly typed programming)

AL objects mentioned

As named in the post. A name that matches one object page by exact type and name links to it; the others stay as named.

Not found in BC28-30: codeunit “ARD_ToExcelByRef”.

Context

  • Features: RecordRef and FieldRef objects, Dynamic field access by ID and index, Record-to-reference conversion, Generic export to Excel, Late binding and runtime resolution, Weakly typed programming patterns

Source: Aardvark Labs, community blog. Summary, key points and quotes are derived (CONTENT-NOTICE.md); read the original for the full text.