Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

What is difference between setautocalcfields & calcfields in business central?

Posted on by 153
Hi Guys,
 
What is difference between setautocalcfields & calcfields in business central? 
and when we can used setautocalcfields or calcfields?
 
Categories:
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,339 Super User 2024 Season 2 on at
    What is difference between setautocalcfields & calcfields in business central?
  • Suggested answer
    TeddyH Profile Picture
    TeddyH 12,868 Super User 2024 Season 1 on at
    What is difference between setautocalcfields & calcfields in business central?
    SetAutoCalcFields is basically CalcFields on looping.
    You use SetAutoCalcFields before looping to increase the performance of your code, so the server knows that it needs to retrieve the value while calling the records.
     
    // Using CALCFIELDS
    IF Customer.FINDSET THEN
    REPEAT
      Customer.CALCFIELDS(Balance,"Net Change");
      … // Do some additional processing.
    UNTIL Customer.NEXT = 0;

    // Using SETAUTOCALCFIELDS for performance
    Customer.SETAUTOCALCFIELDS(Balance,"Net Change");
    IF Customer.FINDSET THEN
    REPEAT  
      … //Do some additional processing.
    UNTIL Customer.NEXT = 0;
  • Suggested answer
    Tech-Lucky Profile Picture
    Tech-Lucky 796 on at
    What is difference between setautocalcfields & calcfields in business central?

    in the case of CALCFIELDS, each FlowField results in a separate query that is not good for performance if you are using this inside the loop.

    The SETAUTOCALCFIELDS is one of the improvements in NAV / BC you should make use of. Any REPEAT … UNTIL loop that contains CALCFIELDS within the loop can benefit from this function. Just set a SETAUTOCALCFIELDS before the FINDSET and all FlowFields you have defined will be calculated with one SELECT command.

    How does that work? Very simple: the SETAUTOCALCFIELDS automatically updates the SELECT query with JOINS for each FlowField. So one query with all your FlowFields calculated.

    the conclusion is SETAUTOCALCFIELDS improves system performance.

    Please verify my answer if this was helpful.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,228 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans