In this post I´ll show seven basic tips for increasing performance when coding in Business Central.

Some of them are well-known as they have been part of C/AL for a long time. And others like partial records were introduced recently.

At the end of the post you will find three Youtube links in which you can dig into more detail about the topics presented.

  • FINDSET VS FINDFIRST
  • PARTIAL RECORDS. SETLOADFIELDS
  • SETAUTOCALCFIELDS
  • CALCSUMS
  • LAZY EVALUATION
  • ISEMPTY
  • SETCURRENTKEY

FINDSET VS FINDFIRST

Use FindSet instead of FindFirst or FindLast when you wish to loop through a series of records.

Also use FindSet(true) when you wish to modify any record in the set, otherwise use FindSet(false).

Only use FindFirst() when you wish to retrieve one record and a loop isn´t needed.

https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/record/record-findset-method

PARTIAL RECORDS. SETLOADFIELDS

SetLoadFields only loads the fields included. Not retrieving the rest of the fields in the table and providing a faster load. Use it to look for specific values as in the example below.

Don´t use it if you need to perform a modify, insert, delete, rename or transferfield of the record as all fields are needed to perform the operations. This will decrease performance and will be counter-productive.

https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/record/record-setloadfields-method

SETAUTOCALCFIELDS

You can improve performance by using the SetAutoCalcFields function before looping through records with FlowFields instead of calling CalcFields on each record in the loop.

https://docs.microsoft.com/en-us/dynamics-nav/setautocalcfields-function–record-

CALCSUMS

Use CalcSums instead of looping through all the records in the table to perform the sum of a specific field or fields. In this example both pieces of code achieve the same result but the last one is better for performance.

https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/record/record-calcsums-method

LAZY EVALUATION

The ‘lazy evaluation’ is an strategy that holds the evaluation of an expression until its value is needed.

The idea is that when we need to evaluate two conditions, always place the fastest first and separated from the other. This way the more intensive operation isn´t executed if it´s not needed.

You will find more information about it in Stefano´s webinar in the link at the end.

ISEMPTY

Use IsEmpty if you just want to know if a record exists but don´t need to know any values.

For example, when using DeleteAll, even if there is nothing to delete the system will still perform a lock. So it´s better to first check if it´s empty and avoid the lock when possible.

https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/record/record-isempty-method

SETCURRENTKEY

Selects a key for the table. It sorts the data of this specific table and allows a better performance for large datasets.

https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/record/record-setcurrentkey-method

Links

Stefano´s webinar at DynamicsCon. I strongly recommend to check it as it has several tips not only for coding but for codeunits, pages, etc.

https://www.youtube.com/watch?v=AwWWUiM1g8Y&t=1655s

Tomas´s webinar at DynamicsCon. Very interesting as he focuses on data structure, keys, performance tests, etc.

https://www.youtube.com/watch?v=g5tigd1TOhU&t=2395s

Business Central Channel. Overall good video for performance tips.

https://www.youtube.com/watch?v=VN7V4GyULtY

Hope you find it useful.


7 Tips For Performance In Business Central

Post navigation


Leave a Reply

Your email address will not be published. Required fields are marked *