Book Image

Extending Microsoft Dynamics NAV 2016 Cookbook

By : Alexander Drogin
Book Image

Extending Microsoft Dynamics NAV 2016 Cookbook

By: Alexander Drogin

Overview of this book

Microsoft Dynamics NAV is an enterprise resource planning (ERP) software suite for organizations. The system offers specialized functionality for manufacturing, distribution, government, retail, and other industries. Its integrated development environment enables customizations with minimal disruption to business processes. The book starts explaining the new features of Dynamics NAV along with how to create and modify a simple module. Moving on, you will learn the importance of thinking beyond the boundaries of C/AL development and the possibilities opened by with it. Next, you will get to know how COM can be used to extend the functionalities of Dynamics NAV. You’ll find out how to extend the Dynamics NAV 2016 version using .NET interoperability and will see the steps required to subscribe to .NET events in order to extend Dynamics NAV. Finally, you’ll see the cmdlets available to manage extension packages. By the end of the book, you will have the knowledge needed to become more efficient in selecting the extending methods, developing and deploying them to the Dynamics NAV, and practicing the best practices.
Table of Contents (17 chapters)
Extending Microsoft Dynamics NAV 2016 Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

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...

  1. Open NAV Object Designer and create a new codeunit.

  2. 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.

  3. 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 the Local attribute. Local functions are visible only inside the object where they are declared and cannot be called from other objects.

  4. Close the declarations window. Now you can see the new function Multiply in the C/AL editor.

  5. 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.

  6. In the Parameters tab, enter the name and the type of a new function parameter you want to declare. Create a parameter X of type Integer. To do this, enter X in the Name field and choose Integer from the drop-down list in the DataType field.

  7. Add one more integer variable, Y:

  8. 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.

  9. We want this function to return the result of the multiplication of two parameters X and Y. EXIT statement serves this purpose, so the function's code should consist of one line: EXIT(X * Y). Start typing the first statement EXIT. 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.

  10. Complete the function. Enter the line EXIT(X * Y);.

  11. Move to the OnRun trigger, declare a local Integer variable Z and start typing the invocation of the function Multiply: 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.