New Functions are Local by Default or Does it change depending on other Settings ?

Today I was working with Microsoft Dynamics NAV 2015. I was developing a sub module and my plan was to create a codeunit and then call its function from a page I created.

So I created a new codeunit and then created several functions. I didn’t change any default settings of functions. 

Then I went on to create my page and it also went pretty good. After that on a action button I was planing to call my codeunit function. Therefore I declared the codeunit as a local variable and tried to check my functions.. WHAT! Functions are not visible. My first impression was “Oh I have not saved it properly” (which is very rare thing to happen).

So I went back to my codeunit and checked it, Functions are still there. 
Then I check the properties of each of these functions and that time I realize Microsoft has change its default behavior

Normally in general codding it is best practice to declare a function as a local function where only within the scope this function can be access. However with earlier versions of Microsoft Dynamics NAV, Microsoft has set this to global, That means from anywhere you can call the functions.

In earlier versions Property “Local” was set to <No>.
With the new Dynamics NAV 2015 it was set to Yes.

I got bit curious and went on to find more details about this and I found this awesome gentlemen blog post (Van Vugt).  

I have quoted his findings in my article and if you want to read the original article please do click here

As for him this setting would be based on Subtype of the code unit.
If the subtype is,
  • Normal (or undefined, i.e. <Normal>) functions will be local by default
  • Test functions by default be global test functions (i.e. FunctionType=Test)
  • TestRunner we get the same behavior as for Subtype Normal
  • Upgrade functions will default to local upgrade functions (i.e.FunctionType=Upgrade)

Thank you and Regards,
Tharanga Chandrasekara.

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?