Warning: number_format() expects parameter 1 to be float, string given in /data/web/virtuals/7298/virtual/www/wp-includes/functions.php on line 425

C/AL + AL: CalcFields

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

Home 9 Development 9 AL Language 9 C/AL + AL: CalcFields ( Page )

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

Directions EMEA

Directions EMEA

Directions4Partners EMEA 2021 is still in progress here in Milan. I want to share all details about each day, but unfortunately, there are so many amazing things to see, watch and try I have almost no time. So today just a few words about the day before the...

read more
Field Level Permissions (Restricted Fields)

Field Level Permissions (Restricted Fields)

I just add a new project to my GitHub repositories. It is a new extension for Business Central that extends security functionalities with field-level permission. Using this extension, users are able to define who can or can not change specific fields in any table in...

read more
Returning complex types in AL Language

Returning complex types in AL Language

In Microsoft Dynamics 365 Business Central 2021 w1 (released in May 2021), a profound change was introduced to ways how we can design our applications Until this version, the only way to return complex data types (like records, codeunits, Lists etc.) was using the var...

read more
Import various file types with Interfaces

Import various file types with Interfaces

A few weeks ago, I described a solution for importing an Excel file to the Business Central using Excel Buffer in AL Language (see here). In today's article, we will look at how to build a more complex solution that can be used for file imports without the needs to...

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