Set values for FlowFilter fields using filtering methods
A common approach for constraining a FlowField calculation is to assign a value to the corresponding FlowFilter field
before calling CalcFields. The assignment compiles and runs without error, but it does not set a filter on the record. CalcFields ignores the assigned value and computes the FlowField across all records instead of the intended subset.
For example, Item."Location Filter" := 'BLUE' followed by Item.CalcFields(Inventory) returns the total inventory across all locations, not just location BLUE. Use SetRange or SetFilter to set FlowFilter values — these methods set the record filter that CalcFields reads when evaluating the FlowField’s CalcFormula.
Example
procedure GetInventory(ItemNo: Code[20]; LocationCode: Code[10]): Decimal
var
Item: Record Item;
begin
Item.Get(ItemNo);
Item."Location Filter" := LocationCode; // Set values for FlowFilter fields using filtering methods [PC0012]
Item.CalcFields(Inventory);
exit(Item.Inventory);
end;Use SetRange to set the FlowFilter to a specific value, or SetFilter for a filter expression:
procedure GetInventory(ItemNo: Code[20]; LocationCode: Code[10]): Decimal
var
Item: Record Item;
begin
Item.Get(ItemNo);
Item.SetRange("Location Filter", LocationCode);
Item.CalcFields(Inventory);
exit(Item.Inventory);
end;