Business Central 2025 Wave 1 (BC26) – SetAutoCalcFields Method on RecordRef

Microsoft Dynamics 365 Business Central 2025 Wave 1 (version 26) introduces several enhancements to developer productivity and platform capabilities. One of the notable changes for AL developers is the new SetAutoCalcFields method added to the RecordRef data type.

This method brings the power of calculated flow fields to the RecordRef context, which previously lacked a built-in way to pre-calculate flow fields without manually invoking CALCFIELDS. Let’s explore what this update means, how it works, and how to use it effectively.

🧠 What is SetAutoCalcFields?

The SetAutoCalcFields method allows developers to specify which flow fields (calculated fields) should be automatically calculated when retrieving a record using the RecordRef data type.

This mimics the behavior of the SetAutoCalcFields method already available on the Record data type, extending it to scenarios where developers work with dynamic tables using RecordRef.

📘 Syntax:

RecordRef.SetAutoCalcFields(Field1, Field2, ...)

🛠️ Example

procedure DemoSetAutoCalcFields()
var
    RecRef: RecordRef;
    FieldRef: FieldRef;
    FieldRefAmount: FieldRef;
begin
    // Open the "Customer" table dynamically
    RecRef.Open(Database::Customer);

    // Get reference to the "Balance" flow field (Field No. = 21 in Customer)
    FieldRefAmount := RecRef.Field(21); 

    // Set the flow field to auto-calculate
    RecRef.SetAutoCalcFields(FieldRefAmount);

    // Find a record
    if RecRef.FindFirst() then begin
        // Now the "Balance" field will be auto-calculated
        Message('Customer Balance: %1', FieldRefAmount.Value);
    end;

    RecRef.Close();
end;

The introduction of the SetAutoCalcFields method on the RecordRef data type in Business Central 2025 Wave 1 is a welcome enhancement for developers. It provides a more efficient and streamlined way to work with AutoCalcFields when using RecordRef, leading to improved application performance and cleaner, more maintainable code.

Stay tuned for more.

Implicit Record and Record Ref Conversion in Business Central AL

When working with Microsoft Dynamics 365 Business Central, one of the most powerful capabilities is the dynamic handling of data using RecordRef. However, as a developer, you may have run into scenarios where you need to switch between the strongly typed Record and the flexible RecordRef—and wondered if there’s a clean way to do it.

Good news: Business Central now supports implicit conversion between Record and RecordRef

📘 Understanding the Core Types:

Before exploring the implicit conversion, it’s crucial to understand the distinct roles of Record and RecordRef:

  • Record: A strongly-typed variable that represents a specific table in the Business Central database. The compiler enforces type safety, ensuring that operations performed on a Record variable are valid for the defined table structure.
  • RecordRef: A more dynamic variable that provides a generic reference to any table in the Business Central database. It allows for runtime manipulation of table structures and data, often used in scenarios like generic data access, metadata exploration, and dynamic query building.

Implicit Conversion – What’s New?

With recent updates, AL now supports implicit conversion:

  • From a Record to a RecordRef
  • From a RecordRef back to a Record (if the types match)

This means cleaner, safer, and more readable code without the boilerplate RecordRef.GetTable() or RecordRef.SetTable().

🔍 Example: Record to RecordRef

procedure LogAnyRecord(rec: RecordRef)
begin
    Message('Table ID: %1', rec.Number);
end;

procedure RunLogging()
var
    customer: Record Customer;
begin
    customer.Get('10000');
    LogAnyRecord(customer); // Implicit conversion from Record to RecordRef
end;

No need for recRef.SetTable(customer) — it’s handled under the hood.

🔄 Example: RecordRef to Record

procedure GetCustomerName(recRef: RecordRef): Text
var
    customer: Record Customer;
begin
    customer := recRef; // Implicit conversion from RecordRef to Record
    exit(customer.Name);
end;

Implicit conversions between Record and RecordRef bring AL language making it easier to write dynamic yet type-safe code. While it’s a small feature on the surface, it greatly enhances developer productivity and code clarity.

Stay Tuned for more updates.