Add documentation for SetAutoCalcFields method#254
Conversation
|
Looks great, do we want to mention you can SetAutoCalcFields on OnOpenPage as far as I recall (do double check), to have the field pre-calculated. Especially useful for lists if you really do need to calculate a field. This is only needed for fields not on the page however, as a FlowField shown on a page will always be calculated. |
Double-checked and added both :) |
JeremyVyska
left a comment
There was a problem hiding this comment.
Agreed, a must-have.
There was a problem hiding this comment.
Pull request overview
This PR adds a new Best Practice documentation page describing how and when to use the SetAutoCalcFields method in Business Central AL to improve FlowField retrieval performance.
Changes:
- Introduces a new Best Practices article for
SetAutoCalcFields, including description and general usage guidance. - Adds guidance for list pages and a comparison between
SetAutoCalcFieldsandCalcFields. - Provides “Bad” vs “Good” AL code examples illustrating the performance impact.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| See the documentation on learn.microsoft.com for more information about [SetAutoCalcFields](https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/record/record-setautocalcfields-method). | ||
|
|
||
| {{% alert title="Note" color="info" %}} | ||
| Starting in Business Central 2025 release wave 1, the SetAutoCalcFields is also available on the RecordRef data type. |
| ## SetAutoCalcFields or CalcFields | ||
| It's best practice to use SetAutoCalcFields when fetching a record since it ensures automatic FlowField calculation. On the other hand, CalcFields should only be used if you already have the record and need to explicitly trigger the calculation. This distinction prevents unnecessary performance overhead, ensuring that database queries remain optimized. |
|
|
||
| ```AL | ||
| Customer.SetFilter(Balance, '>%1', LargeCredit); | ||
| Customer.SetAutoCalcFields(Balance) |
| ### Bad Code | ||
|
|
||
| ```AL | ||
| Customer.SetFilter(Balance, '>%1' , LargeCredit); |
Uh oh!
There was an error while loading. Please reload this page.