D365 Business Central - Use of SetLoadFields (Coding for Performance)

The partial records capability in Business Central is available from Business Central 2020 release wave 2 (Version 17).
The partial records capability in Business Central allows for loading a subset of normal table fields when accessing a SQL based data source. Using partial records improves performance of objects like reports and OData pages - objects whose source code loops through records. It is particularly beneficial when table extensions are used in the application.

Accessing a data source from AL code is typically done by using the record's methods GET, FIND, NEXT, and so on.

SetLoadFields is very good feature of Business Central 2020 release wave 2. By using SetLoadFields we can make execution of our code faster and give more performance.

We can use SetLoadFields to set which fields we want to load in our operation and the FindSet() will only retrieve those fields.

In below Steps we will discuss how we can use SetLoadFields. For example, we consider the scenario where we need calculate the sum of the “Unit Cost” for the selected list of items and need to show the Total Unit Cost for those items in Message while opening Item List Page.

Step 1: Firstly, we will create new pageextension that will extend the Item List Page -

Step 2: Now we will add our code on “OnOpenPage” trigger of PageExtension to calculate the sum of “Unit Cost” for the selected Items-

Step 3: Once you have added the above code, then build and Publish the package and Click on Item List Page-

You can see the Total Unit Cost is displayed in the message while Opening Item List.

In above scenario we have to calculate the “Unit Cost” only and we do not require the other fields of the table to be loaded.

Hence we have only loaded the “Unit Cost” fields by SetLoadFields, as we need “Unit Cost” field in our Findset() operation. it will make our code much faster while execution.

You should not use partial record loading if you are doing INSERT, MODIFY, DELETE operations or if you are using temporary records because in this case it is required that the record is fully loaded.

Along with SetLoadFields there are other Load functions that are available for partial records (AddLoadFields, LoadFields,AreFieldsLoaded)





Specifies a set of fields to be initially loaded when the record is retrieved from its data source.



Adds fields to the current set of fields to be initially loaded when the record is retrieved from its data source.



Checks whether the specified fields are all initially loaded.



Accesses the table’s corresponding data source to load the specified fields.


Hope this helps!!

Comment List