---
id: post/aardvarklabs-blog/3118
type: post
title: Leveraging RecordRef and FieldRef for Dynamic Coding
summary: 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.
tier: community
language: en
tags:
  - recordref
  - fieldref
  - weakly typed
  - dynamic coding
  - al language
  - generic code
system: development
review:
  state: reviewed
  by: opus
  at: "2026-10-08T01:56:14.110Z"
  flags: []
generated:
  at: "2026-10-08T01:26:53.141Z"
  pipeline: 0.2.0
  prompts:
    extract-post: 1
  input_hash: add1331c1b2ad1da923d6407c40758f244b6c1474c95b686dd6b29c2cc6e6467
evidence:
  - kind: blog
    url: https://aardvarklabs.blog/2026/03/06/leveraging-recordref-and-fieldref-for-dynamic-coding/
    title: Leveraging RecordRef and FieldRef for Dynamic Coding
    date: "2026-03-06"
    commit: null
    t: null
    quote: null
  - kind: blog
    url: https://aardvarklabs.blog/2026/03/06/leveraging-recordref-and-fieldref-for-dynamic-coding/
    title: Leveraging RecordRef and FieldRef for Dynamic Coding
    date: "2026-03-06"
    commit: null
    t: null
    quote: With all these advancements, why would we want to use a Weakly Typed object? Fantastic question hypothetical reader! In a word, flexibility.
links:
  learn: []
  objects:
    - object/table/36
    - object/table/112
    - object/table/27
    - object/table/370
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
post_id: "3118"
source_id: aardvarklabs-blog
source_name: Aardvark Labs
url: https://aardvarklabs.blog/2026/03/06/leveraging-recordref-and-fieldref-for-dynamic-coding/
published_at: "2026-03-06T13:00:00.000Z"
author: Marcel Chabot
full_text: false
words: 1499
quotes:
  - text: With all these advancements, why would we want to use a Weakly Typed object? Fantastic question hypothetical reader! In a word, flexibility.
    why_it_matters: Identifies the core motivation for using weakly typed objects despite the strong benefits of strongly typed programming
code_objects_mentioned:
  - table Sales Header
  - table Sales Invoice Header
  - table Item
  - table Excel Buffer
  - codeunit ARD_ToExcelByRef
systems:
  - development
  - platform
versions_mentioned: []
preview:
  embeddable: true
  frame_url: https://aardvarklabs.blog/2026/03/06/leveraging-recordref-and-fieldref-for-dynamic-coding/embed/
  image: https://aardvarklabs.blog/wp-content/uploads/2026/03/create-a-featured-image-for-a-blog-post-titled-leveraging.png
  image_alt: null
  image_w: 1024
  image_h: 768
  site_name: Aardvark Labs
  favicon: https://aardvarklabs.blog/wp-content/uploads/2024/04/design-1.png?w=32
  probed_at: "2026-10-07T11:50:56.063Z"
---

# Leveraging RecordRef and FieldRef for Dynamic Coding

[Read the post](https://aardvarklabs.blog/2026/03/06/leveraging-recordref-and-fieldref-for-dynamic-coding/) · Aardvark Labs (Marcel Chabot) · 2026-03-06 · 1499 words · tier community · reviewed (checked by Opus)

> 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.

## 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"](../../objects/table/36.md)
- [table 112 "Sales Invoice Header"](../../objects/table/112.md)
- [table 27 "Item"](../../objects/table/27.md)
- [table 370 "Excel Buffer"](../../objects/table/370.md)
- codeunit "ARD_ToExcelByRef"

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.
