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
"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.
- table 36 “Sales Header”
- table 112 “Sales Invoice Header”
- table 27 “Item”
- table 370 “Excel Buffer”
- codeunit “ARD_ToExcelByRef”
Not found in BC28-30: codeunit “ARD_ToExcelByRef”.
Possibly related
No source states these links: they share an object, a model read them, or a person found the same subject.
- 🧩 Deriving dimensions in Business Central beyond Default Dimensions — possibly related: both name Table 112 “Sales Invoice Header”
- BC 29 lets a single index span base table and table extension fields — possibly related: both name Table 112 “Sales Invoice Header”
- BC Friday Tips #56 Understand Missing Fields in Copy Documents — possibly related: both name Table 112 “Sales Invoice Header”
- BC Friday Tips #69 Item Blocked Fields — possibly related: both name Table 27 “Item”
- BC Friday Tips #74 Copy Document and Custom Field — possibly related: both name Table 112 “Sales Invoice Header”
- BC Friday Tips #84 Why Is Your Item Missing from the Sales Line Lookup? — possibly related: both name Table 27 “Item”
- Business Central 2025 wave 2 (BC27): App version in “Copy error details”/”Share details via” — possibly related: both name Table 27 “Item”
- D365 Business Central: How to Fix Missing Sales Invoices in the API — possibly related: both name Table 112 “Sales Invoice Header”
- Dynamics 365 Business Central: “Hide Company Bank Account” setup in General Ledger Setup (Update Company Bank Account on posted documents) — possibly related: both name Table 112 “Sales Invoice Header”
- Dynamics 365 Business Central: compressing API responses at max. — possibly related: both name Table 27 “Item”
Heads up
- gotcha: “What if Microsoft refactors the Amount field to something other than field Id 60?”
- gotcha: “What if they move a table? We are at risk that Microsoft or an ISV changes their extension and breaks our references.”
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.