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

Importing and exporting application objects


Dynamics NAV application objects can be exported in plain text format and edited with external tools. Although editing code outside C/SIDE is not as convenient as doing it in the C/SIDE code editor, this may be useful when, for example, you need to compare different versions of the same object with a file comparison program or export the source file into a code repository.

Objects can also be exported and imported in binary format as .fob files. Binary files cannot be edited directly, so the format is convenient when you do not want to disclose the internal application code. Besides, .fob files do not require a developer's license to be imported, and therefore are used to deploy objects on the customer's site.

How to do it...

First let us export an object into a text file and edit it outside C/SIDE editor.

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

  2. In the OnRun trigger, add a single line of code:

            MESSAGE('Hello World'); 
    
  3. Click Save, fill in the ID and Name fields: 50003 HelloWorld, close the code editor.

  4. Select the codeunit 50003 in the object designer and click Export in the File menu.

  5. Choose the folder where you want to export the codeunit to and name the file COD50003.txt.

  6. Select Text Format (*.txt) in the File Type drop-down list and click Save.

  7. In a file manager, locate the file COD50003.txt and open it in a text editor. This is how the exported object looks in a text editor:

            OBJECT Codeunit 50003 Hello World 
            { 
              OBJECT-PROPERTIES 
              { 
                Date=22.07.16; 
                Time=23:44:09; 
                Modified=Yes; 
                Version List=; 
              } 
              PROPERTIES 
              { 
                OnRun=BEGIN 
                MESSAGE('Hello World'); 
                END; 
     
              } 
              CODE 
              { 
     
                BEGIN 
                END. 
              } 
            } 
    
  8. In the object text locate the line MESSAGE('Hello World'); and replace the message text, MESSAGE('Exported NAV object');.

  9. Save the object and close the editor.

  10. Return to NAV object designer, click Import from the File menu, select Text Files in the file type filter, and choose the file COD50003.txt.

  11. Click Design in the object editor window and review the object code. It contains code modified outside of the C/AL editor.

    Note

    If the object you are importing already exists in the application, it will be replaced with the new version without warning. Any changes made to the object will be lost.

  12. In the object designer, select the codeunit 50003 we created in the previous step and click Export in the File menu.

  13. Select Dynamics NAV Object Format (*.fob) in the File Type drop-down list.

  14. Choose the folder where you want to export the codeunit to and name the file COD50003. It will be automatically assigned an extension .fob. Save the file.

  15. Back in the object designer click Design to edit the codeunit and replace the message text with the empty string: MESSAGE(''). Then save the codeunit and close the code editor.

  16. In the object designer, click Import from the File menu. In the Import Objects dialog, select Dynamics NAV Object Files in the file type filter, locate the file COD50003.fob, and click Open.

  17. C/SIDE will warn you that there is an object with conflicting versions in the database. Click OK to switch to Import Worksheet:

  18. Click OK to import the object replacing the codeunit existing in the database.

How it works...

When importing application objects in plain text format, C/SIDE does not check objects for possible conflicts. Merging code must be done manually by the developer.

Binary files are automatically checked for conflicts during the import if there are objects with the same ID in the database and in the file being imported. If both files have the Modified flag checked, this is considered as a conflict that must be resolved in the Import Worksheet dialog. In the Action field, you can choose how to handle conflicting objects. Possible options are:

  • Replace to replace the object in the database with the new one.

  • Skip to leave the existing object unchanged and ignore the new object.

  • Merge to automatically merge changes from both objects (only applicable for tables)