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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.