How To: Usage of SETAUTOCALCFIELDS in NAV

Optimization2
FacebookTwitterGoogle+LinkedInWhatsAppEvernoteShare

One of the functionalities I personally feel most developers do not use and they should, for it adds performance to long lasting processes compared to its predecessor is SETAUTOCALCFIELDS.

This function was introduced in NAV2013 and is not available in versions priors to that one.

SETAUTOCALCFIELDS enables working with flowfields in a more efficient and proper way in loops and data searching structures.

For instance, we could replace the next piece of code:


Cust.RESET;

IF Cust.FINDSET THEN

REPEAT

  Cust.CALCFIELDS(Balance); // This is not as efficient 

  { more code here }

UNTIL cust.NEXT=0;

For something alone the lines of:


Cust.RESET;

Cust.SETAUTOCALCFIELDS(Balance); // This will automatically calculate the Balance for each row

IF Cust.FINDSET THEN

REPEAT

  { more code here }

UNTIL cust.NEXT=0;

 

From a user’s point of view the result will be exactly the same, but looking at it from a developer’s point of view it will not.

With the usage of this tool we can optimize execution times of time consuming processes and save resources.

 

BEWARE!

Just like a filter, the SETAUTOCALCFIELDS will be active until we say otherwise.

To disable the automatic calculation we can do it this way:


Cust.SETAUTOCALCFIELDS; // Without additional parameters

 

Also it should be noted that if we assign a variable with the SETAUTOCALCFIELDS active to another variable (same table ID) this function will not be transferred. But if we use the COPY function it will be transferred.


//Item Record@27

//Item2 Record@27

Item2.SETAUTOCALCFIELDS(Inventory);

Item := Item2; // "Item" does not have SETAUTOCALCFIELDS active

Item.COPY(Item2); // "Item DOES have SETAUTOCALCFIELDS active

For more information you can always check the Microsoft page.

 

Leave a Comment.