NAV Development Environment - C/SIDE
C/SIDE is the NAV integrated development environment where we create application objects, design the user interface, and write code. The next recipe gives an overview of the environment and presents some new features introduced to the IDE in NAV 2016.
How to do it...
- Open NAV Object Designer and create a new codeunit.
- In the C/AL Code Editor window, click C/AL Globals in the View menu to access the list of global variables, text constants, and functions.
- Select the Functions tab in the C/AL Globals window and type the function name. Name the new function
Multiply
. By default, a new function is created with theLocal
attribute. Local functions are visible only inside the object where they are declared and cannot be called from other objects. - Close the declarations window. Now you can see the new function
Multiply
in the C/AL editor. - Position the cursor on an empty line inside the function and open the C/AL Locals window. Here you can declare local variables available inside the function, as well as the function's parameters and return type.
- In the Parameters tab, enter the name and the type of a new function parameter you want to declare. Create a parameter
X
of typeInteger
. To do this, enterX
in the Name field and chooseInteger
from the drop-down list in the DataType field. - Add one more integer variable,Â
Y
: - Switch to the Return Value tab and fill the Return Type field. Select Integer in the list of types. Close the window and review the changes to the function in the code editor. Now you have declared a function that takes two Integer parameters and returns an Integer result.
- We want this function to return the result of the multiplication of two parameters
X
andY
.EXIT
statement serves this purpose, so the function's code should consist of one line:EXIT(X * Y)
. Start typing the first statementEXIT
. As you type, IntelliSense will suggest possible language structures:When you see the function EXIT in the suggested autocompletion list, select it by pressing the up and down keys on the keyboard and press Enter to confirm the selection.
- Complete the function. Enter the lineÂ
EXIT(X * Y);
. - Move to the
OnRun
trigger, declare a local Integer variableZ
and start typing the invocation of the functionMultiply: Z := Multiply(5,8)
. As you type the first symbols of the function name, IntelliSense will show a list of suggestions. After you type the opening bracket before entering the function arguments, IntelliSense will show the parameter names and types along with the function return type:
How it works...
Unlike many other programming languages, like C++, C# or Java, variables and functions declaration in C/SIDE are separated from the program text. All global and local declarations are accessed in the code editor via the main menu.
Variables and text constants declared in the C/AL Locals can be used only in the function where they are created. C/AL Globals declarations are accessible from any function in the same object.
Functions can only be created in the C/AL Globals and can be accessed from anywhere in the same object. Function do not have to return a value and can be declared without any return type. If you want the function to return a result, you must assign a return type to it and use the EXIT
statement to return a value to the caller function.
In the steps from Step 7 to Step 11 we demonstrate how IntelliSence integrates with the NAV development environment. IntelliSense is a Microsoft code completion feature widely used in Visual Studio. It aides a developer in coding by suggesting possible variable and function names, function parameters, and many other things. Such code hints speed up coding and reduce the risk of typos, and many plain coding mistakes.