Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Extending Microsoft Dynamics NAV 2016 Cookbook

You're reading from   Extending Microsoft Dynamics NAV 2016 Cookbook Extend Dynamics NAV 2016 to win the business world

Arrow left icon
Product type Paperback
Published in Jan 2017
Publisher Packt
ISBN-13 9781786460608
Length 458 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Alexander Drogin Alexander Drogin
Author Profile Icon Alexander Drogin
Alexander Drogin
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Writing Basic C/AL Code FREE CHAPTER 2. Advanced C/AL Development 3. Reporting and Data Analysis 4. .NET Interoperability in C/AL 5. Extending C/AL with COM Components 6. SharePoint Integration 7. Control Add-ins 8. Web Services 9. Events and Extension Packages 10. PowerShell

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:

    How to do it...

  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:

    How to do it...

    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 to do it...

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.

You have been reading a chapter from
Extending Microsoft Dynamics NAV 2016 Cookbook
Published in: Jan 2017
Publisher: Packt
ISBN-13: 9781786460608
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime