This time I want to discuss Record.SetLoadFields Method, a new method from Dynamics 365 Business Central 2020 Wave 2 (BC17).
This method is part of the partial records capability for improving performance, 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’s particularly beneficial when table extensions are used in the application.
Using Partial Records
As you can see in the below sample, you can use SetLoadFields to set which fields you want to retrieve in your operation and the next FindSet() will retrieve only those fields. This will improves performance of Business Central.
But If you try to access a new field that was not set by SetLoadFields, in this case the platform performs an implicit GET operation on the record and loads that missing field.
Although you can get the same result, please don’t add fields after SetLoadFields directly.
Bad code sample:
Good code sample:
1. There are no warnings on using fields not set by SetLoadFields until now. So notice that the call to SetLoadFields occurs before the data fetching operations.
2. For performance reasons, it’s not recommended to use partial records on a record that will do inserts, deletes, or copies to temporary records. All these operations require that the record is fully loaded, so you lose the performance gains of loading fewer. For this reason, the feature is especially advantageous in reading-based scenarios.
Hope this will help.