C/AL + AL: CalcFields

by Mar 19, 2019AL Language, C/AL Language

Home 9 Development 9 AL Language 9 C/AL + AL: CalcFields

CalcFields is a method to calculate the FlowFields in a record.

Flowfields are special fields (virtual) that are not stored physically in the database/table. Standard fields are loaded once the record is retrieved from the database. However, as the flowfields are virtual and show data (or grouped data) from another table, calculating these fields means to query another table with another SQL statement. As this can (and usually is) very performance-intensive task, FlowFields are not automatically calculated when the record is loaded from the database.

For fields shown on pages, values are automatically loaded (as if the field is shown on the page, it is usually intended to show the value of the field. However, if a developer works with FlowField in AL or C/AL language and needs to work with its value, the value must be calculated manually first (using CalcFields method).

See example below

 SalesHeader.SetRange("Document Type", SalesHeader."Document Type"::Order);
 SalesHeader.SetRange("Date Filter", 010119D, 123119D);
 if SalesHeader.FindSet() then
   repeat
     // Nothing is shown as the FlowField is not calculated
     // Shown message: "Order XYZ: 0"
     Message('Order %1: %2', SalesHeader."No.", SalesHeader.Amount);

     // Calculate Amount field using CalcFields method
     SalesHeader.CalcFields(Amount); 

     // Now the message show right Amount of each Sales Order
     // Shown message: "Order XYZ: 123 665.23"
     Message('Order %1: %2', SalesHeader."No.", SalesHeader.Amount);
   until SalesHeader.Next() < 1; 

Recent Articles from the category

Isolated events

Isolated events

With Business Central 2022 wave 1, a new setting for event publishers was introduced. Until this version, any error in any event subscriber caused interruption to the current running process and stopped the whole activity. In some cases (such as log-in), this is...

read more
Custom Filter Tokens

Custom Filter Tokens

As a user of the Business Central you have some constants you can use to filter or insert values. These constants contain useful values for data manipulation such as t / today for date field - return current dateq / quarter for date field filters - return range of the...

read more
How to let users choose field(s) properly

How to let users choose field(s) properly

When some complex functionality is developed, it is sometimes necessary to let users choose a specific field. This can be required for field permissions, mapping imported values or any similar process. Earlier, the usual way was to create a link on the Field table...

read more
Working with Translation Files (XLIFF)

Working with Translation Files (XLIFF)

How does the translation file work? In Microsoft Dynamic 365 Business Central, displaying different languages is done using the XLIFF files extension (.xlf). The generated XLIFF files have strings that are specified in properties like Captions, Tooltips......

read more
1D & 2D Barcodes in Business Central 19.1

1D & 2D Barcodes in Business Central 19.1

Business Central (cloud-only!) includes one-dimensional (1D) barcode fonts since Microsoft Dynamics 365 Business Central 2020 wave 2 (17.0) was released in October 2020. It is a great improvement to how developers can handle requirements from their clients to print...

read more
ErrorInfo data type & Collectible Errors

ErrorInfo data type & Collectible Errors

A major change to AL Language development is here! Collectible errors can hugely improve any validation procedures. And what's new? Everything is about a new data type ErrorInfo. ErrorInfo data type ErrorInfo is a new data type introduced in Microsoft Dynamics 365...

read more
Exploring CosmosDB with Business Central, part 2

Exploring CosmosDB with Business Central, part 2

This part explains how to connect to Azure Cosmos DB from your Business Central extension using AL Language and how to get some values from the database.------------------------------------------------------------------------------------------------------------------...

read more
DynamicsCon 2021 session recording available!

DynamicsCon 2021 session recording available!

Finally, recordings from DynamicsCon 2021 Autumn edition are available! Check the official youtube channel. It was a great conference with over 250 people during my live session! I definitely hope I will be able to attend the next in-person DynamicsCon as a speaker...

read more

Sign Up for News

Certifications

Highest certification
Microsoft Data Management and
also in D365 Business Central

Microsoft Certified: Dynamics 365 Business Central Functional Consultant Associate

See other certifications here