Description
There appears to be conflicting guidance regarding the recommended order of SetRange / SetFilter and SetLoadFields.
The AL Guidelines explicitly mark the following order as bad code:
Item.SetLoadFields("Item Category Code");
Item.SetRange("Third Party Item Exists", false);
Item.FindFirst();
They recommend applying the filter first:
Item.SetRange("Third Party Item Exists", false);
Item.SetLoadFields("Item Category Code");
Item.FindFirst();
Source:
https://github.com/microsoft/alguidelines/blob/main/content/docs/BestPractices/SetLoadFields/Index.md#bad-code-1
However, the BCQuality good example uses the opposite order:
Customer.SetLoadFields(Name);
Customer.SetRange("Country/Region Code", 'US');
if Customer.FindSet() then
Source:
|
Customer.SetLoadFields(Name); |
|
Customer.SetRange("Country/Region Code", 'US'); |
|
if Customer.FindSet() then |
|
repeat |
|
Message(Customer.Name); |
|
until Customer.Next() = 0; |
|
end; |
|
|
|
procedure LookupSkuPolicy(LocationCode: Code[10]) Policy: Enum "SKU Creation Method" |
|
var |
Microsoft Learn states that SetLoadFields configures the fields for subsequent record loads and that fields used for filtering are loaded automatically. It does not appear to specify a required order between SetRange and SetLoadFields.
Question
Which pattern should BCQuality document?
Should the BCQuality example be changed to match the AL Guidelines?
Does BCQuality intentionally recommend a different order?
If both variants are valid, should that be stated explicitly to avoid contradictory guidance?
Expected outcome
The repositories should provide consistent guidance and clearly state whether the order is technically relevant or only a coding convention.
Description
There appears to be conflicting guidance regarding the recommended order of
SetRange/SetFilterandSetLoadFields.The AL Guidelines explicitly mark the following order as bad code:
They recommend applying the filter first:
Source:
https://github.com/microsoft/alguidelines/blob/main/content/docs/BestPractices/SetLoadFields/Index.md#bad-code-1
However, the BCQuality good example uses the opposite order:
Source:
BCQuality/microsoft/knowledge/performance/use-setloadfields-for-partial-records.good.al
Lines 7 to 16 in 8fb7f61
Microsoft Learn states that
SetLoadFieldsconfigures the fields for subsequent record loads and that fields used for filtering are loaded automatically. It does not appear to specify a required order betweenSetRangeandSetLoadFields.Question
Which pattern should BCQuality document?
Should the BCQuality example be changed to match the AL Guidelines?
Does BCQuality intentionally recommend a different order?
If both variants are valid, should that be stated explicitly to avoid contradictory guidance?
Expected outcome
The repositories should provide consistent guidance and clearly state whether the order is technically relevant or only a coding convention.