Hi, Readers.
The public preview for Dynamics 365 Business Central 2025 release wave 1 (BC26) is available. Learn more: Link.
I will continue to test and share some new features that I hope will be helpful.
This new feature is not yet documented in the Business Central 2025 release wave 1 (BC26) release plan but is mentioned in AL Language extension changelog Version 15.0.
Added SetAutoCalcFields on the RecordRef data type.
https://marketplace.visualstudio.com/items/ms-dynamics-smb.al/changelog

FlowFields in Business Central are virtual fields. The values in these fields are not saved in the table. This means that you must use either the CalcFields method or the SetAutoCalcFields Method (Record) to update them.
For Example: If you forget to use CalcFields method to calculate a flowfield (Inventory), the value will be 0.


So you first have to use CalcFields method to calculate a flowfield.

Then you can get the value.

You can improve performance by using the SETAUTOCALCFIELDS method before looping through records with FlowFields instead of calling the CALCFIELDS method on each record in the loop.
For example:


More details: Dynamics 365 Business Central: FlowFields (Sum, Average, Exist, Count, Min, Max, Lookup)
But until now, the RecordRef Data type does not support the SetAutoCalcFields Method (Record).
PS: The RecordRef Data typecan refer to any table in the database, generally used with FieldRef Data type.
With this wave (BC26), Microsoft added SetAutoCalcFields method on the RecordRef data type.👏👏👏
procedure SetAutoCalcFields([Fields: Integer, …]): Boolean
Sets the FlowFields that you specify to be automatically calculated when the RecordRef is retrieved from the database.

PS:
If AL language has been upgraded to 15.0 or above
‘SetAutoCalcFields’ is not available in runtime version ‘14.0’. The supported runtime versions are: ‘15.0’ or greater. AL AL0666

If AL language is not upgraded to 15.0 or above:
‘RecordRef’ does not contain a definition for ‘SetAutoCalcFields’ AL AL0132

Let’s look at a detailed example, add an action to the Customer List page to sum up the Balance of all customers.



Great.

Give it a try!!!😁
Test code:
pageextension 50119 CustomerListExt extends "Customer List"
{
actions
{
addafter("Co&mments")
{
action(SumAAllBalance)
{
Caption = 'Sum all Balance';
ApplicationArea = All;
Promoted = true;
PromotedCategory = Process;
Image = NewSum;
trigger OnAction()
var
RecRef: RecordRef;
FldRef: FieldRef;
TotalBalance: Decimal;
CurrentBalance: Decimal;
begin
RecRef.Open(Database::Customer);
RecRef.SetAutoCalcFields(58); // Balance
FldRef := RecRef.Field(58); // Balance
if RecRef.FindSet() then
repeat
Evaluate(CurrentBalance, Format(FldRef));
TotalBalance += CurrentBalance;
until RecRef.Next() = 0;
Message('Total Balance: %1', TotalBalance);
end;
}
}
}
}
END
Hope this will help.
Thanks for reading.
ZHU
コメント