LC0074 - StefanMaron/BusinessCentral.LinterCop GitHub Wiki
FlowFilter
fields using filtering methods.
Set values for This rule detects direct assignments to FlowFilter
fields in AL code. Directly assigning values to these fields bypasses their intended functionality and invalidates the filtering logic used for calculations in FlowField fields. Instead, you should use the .SetFilter()
or .SetRange()
methods to properly set filters and ensure accurate results.
Example
procedure GetInventory(ItemNo: Code[20]; LocationCode: Code[10]): Decimal
var
Item: Record Item;
begin
Item."No." := ItemNo;
Item."Location Filter" := LocationCode; // Direct assignment to a FlowFilter field
Item.CalcFields(Inventory);
exit(Item.Inventory);
end;
This now returns Inventory of all the Location Codes. The right way to handle this is using the .SetFilter()
or .SetRange()
method.
procedure GetInventory(ItemNo: Code[20]; LocationCode: Code[10]): Decimal
var
Item: Record Item;
begin
Item."No." := ItemNo;
Item.SetRange("Location Filter", LocationCode);
Item.CalcFields(Inventory);
exit(Item.Inventory);
end;