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

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:

    How to do it...

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