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.
- Open NAV object designer and create a new codeunit.
- In the
OnRun
trigger, add a single line of code:Â Â Â Â Â Â Â MESSAGE('Hello World');
- Click Save, fill in the ID and Name fields: 50003 HelloWorld, close the code editor.
- Select the codeunit
50003
in the object designer and click Export in the File menu. - Choose the folder where you want to export the codeunit to and name the file
COD50003.txt
. - Select Text Format (
*.txt
) in the File Type drop-down list and click Save. - 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.       }       }
- In the object text locate the line
MESSAGE('Hello World');
and replace the message text,ÂMESSAGE('Exported NAV object');
. - Save the object and close the editor.
- 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
. - 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.
- In the object designer, select the codeunit
50003
we created in the previous step and click Export in the File menu. - Select Dynamics NAV Object Format (*.fob) in the File Type drop-down list.
- 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. - 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. - 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. - C/SIDE will warn you that there is an object with conflicting versions in the database. Click OK to switch to Import Worksheet:
- 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)