alguidelines/content/docs/BestPractices/SetLoadFields/Index.md
2023-06-06 10:52:52 +02:00

1.2 KiB

title tags categories
SetLoadFields
AL
Readability
Best Practice

See the documentation on learn.microsoft.com for more information about SetLoadFields.

For the performance of your code it is important that you use SetLoadFields as much as possible.

If you want to retrieve a record from the database to check if the record is available the advice is to set an SetLoadFields on the primary key fields of the table so only those fields will be retrieved from the database.

Bad code

if not Item.Get(ItemNo) then 
    exit();

Good code

Item.SetLoadFields("No.");
if not Item.Get(ItemNo) then
    exit();

Place the SetLoadFields in the code before filtering the record (there is no need to record filterfields in the SetLoadFields).

Bad code

Item.Setrange("Third Party Item Exists", false);
Item.SetLoadFields("Item Category Code");
Item.Get(ItemNo);

Good code

Item.SetLoadFields("Item Category Code");
Item.Setrange("Third Party Item Exists", false);
Item.Get(ItemNo);