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

BC Open Source? How to start?

BC Open Source? How to start?

BC Open Source? How to start? One of the most exciting news introduced last month in Lyon during Directions EMEA 2023 was the changes to the open-source initiative. This means that you can now contribute to the source code of the Base app and the System app, which are...

read more
Validate a FlowField Field. Wait? What?

Validate a FlowField Field. Wait? What?

Validate a FlowField Field. Wait? What? There are not many things in the AL Language that surprised me. However, last week, I found one such thing - I reviewed customizations made by another partner and had to analyze the OOTB code of the Demand Forecast matrix. I run...

read more
Dynamics NAV 2013 & Expired Cronus License

Dynamics NAV 2013 & Expired Cronus License

We found an interesting problem - we were not able to run the development environment for Dynamics NAV 2013. Whenever we tried to run the development client, we got the following error message: "Your program license has expired" and the development client has closed...

read more
Indirect Dependencies and Access Modifiers

Indirect Dependencies and Access Modifiers

Last week, there was a discussion on Yammer on how to get values from the "Sent Email" record when all fields are marked as Internal. I was surprised that many people do not know what can/can't access modifiers (such as local, protected, or internal) be used for. I...

read more
Clean up your copied environments

Clean up your copied environments

One of the most important things every developer should handle is to clean up the environment when the environment (or a company) is copied. Especially if the environment is managed directly by a client and they can create new copies anytime. Similarly, for copied...

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