Different use of AL Find Functions for Filters in Dynamics 365 Business Central

This post provides tips about different find function in Business Central, including both long-standing C/AL strategies and newer concepts like partial records.

FindSet vs FindFirst/FindLast

FindSet and FindFirst/FindLast are two methods utilized in Dynamics 365 Business Central for extracting records from a table. The key distinction between them is that FindSet fetches a group of records, whereas FindFirst only fetches the initial record in the filter and FindLast fetches the last record.

FindSet is employed when there’s a need to traverse through a sequence of records, and it’s advisable to use FindSet(true) if there’s a requirement to alter any record within the group. Conversely, FindFirst/FindLast is employed when only the initial or last record is needed and there’s no requirement for a loop.

SetLoadFields 

The SetLoadFields function only loads the specified fields, thereby not fetching the remaining fields in the table and ensuring a quicker load. It is suitable for searching for specific values, as illustrated in the example below.


However, it should not be used if you need to carry out operations such as modify, insert, delete, rename, or TransferField on the record, as all fields are required for these operations. Doing so would reduce performance and prove counterproductive.

SetAutoCalcFields


We used to call CalcFields function to calculate flowfields. But in any loop each time calling the CalcFields is not efficient. For this now we can improve performance by using the SetAutoCalcFields function before looping through records with FlowFields


Comments

Popular posts from this blog

How to create documentation comment using Custom Snippets in VS Code for AL - D365 Business Central.

Microsoft Dynamics NAV - Creating and Consuming a Codeunit Web Service