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

Compiling objects and error handling


The C/AL code in NAV objects is not executable itself. Before a C/AL object can be used in the application, it must be compiled into binary code that can be run.

The C/AL compiler is a part of the C/SIDE development environment, and can be run either from the object designer or in the code editor while writing the application code.

How to do it...

  1. Open NAV object designer and create a new codeunit.

  2. In the OnRun trigger, declare a local variable CurrDate of type Integer:

    Name

    DataType

    CurrDate

    Integer

  3. Add two code lines in the OnRun trigger:

            CurrDate := TODAY; 
            MESSAGE('Today is %1,CurrDate); 
    
  4. The preceding code contains two errors. Let's try to compile it. Press F11 or click Compile in the Tools menu to compile the code. A message will inform you about an incorrect type conversion and position the cursor in the line containing the first error.

  5. Click Save in the File menu, assign an ID and name to the new codeunit, uncheck the Compiled checkmark in the dialog box, and click OK:

  6. The object is saved without compiling. The Compiled column in object designer does not have a checkmark, which indicates that the object is uncompiled:

    Note

    Uncompiled objects cannot be executed.

  7. Select the codeunit 50002 and click Run in the object designer. An error message will inform you that the object must be saved in the compiled form before it can be run.

  8. Close the message dialog and click Design.

  9. To fix the first error in the code, open C/AL Locals in the OnRun trigger and change the data type of the CurrDate variable. Replace Integer with Date.

  10. After fixing the error, Click Compile. This time, compilation will stop on the second line informing you about a syntax error.

  11. Insert the missing apostrophe to close the text constant and fix the erroneous line. The following is the correct function code:

            CurrDate := TODAY; 
            MESSAGE('Today is %1',CurrDate); 
    
  12. Save the object, this time with the Compiled option, and run it from the object designer.

How it works...

Each of the two lines at the beginning of this exercise contains an error. In the first line we are assigning a date to an integer variable, and the second line is missing an apostrophe closing the text constant. When an object is compiled, only the first error is shown if the compilation breaks. Errors must be fixed one by one.

In Step 5 we are saving the object without compiling. This option is often used in the middle of the development process, when the object is incomplete and not syntactically correct yet.

It is not necessary to open objects in the code editor to compile them one at a time. It is possible to compile multiple objects in one batch. Select all objects you want to compile in the object designer and press F11 - it will run compilation for all selected objects. If several objects are selected and there are compilation errors in any of them, the list of errors will be displayed in a summary table.