CALCFIELDS and CALCSUMS comparison

In the Sales Header record, there are FlowFields defined for Amount and "AmountIncludingVAT". These FlowFields are all based on Sums of entries in the SalesLine table. The CalcFormula for Amount is Sum("SalesLine".AmountWHERE(DocumentType=FIELD(DocumentType), DocumentNo.=FIELD(No.))).

CALCSUMS can be used on any integer, big integer, or decimal field with any filter on any table, but for larger datasets creating a key with a SumIndexField is recommended.

To calculate a TotalOrderAmount value while referencing the Sales Header table, the code can be as simple as this:

"Sales Header".CALCFIELDS (Amount);TotalOrderAmount := "Sales Header".Amount;

To calculate the same value from code directly referencing ...

Get Programming Microsoft Dynamics NAV - Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.