DataMigrate Pro command overview

Register product

You will receive the secret-key with the demo license or by e-mail after placing your official order

DataMigratePro --registration <secret-key> --tenantid <TenantID>

Define interfaces

Both the SQL Server database and the Business Central instance must be made known to the program for further work.

To enable data transfer, a so-called app resource must be created and configured in Business Central and provided with the corresponding authorizations. Further details can be found in the documentation How to Register Business Central App with API Permissions in Azure Portal – NAVUSER

DataMigratePro /
  --sqlconnection "Data Source=localhost;Initial Catalog=Demo Database NAV (6-0);Integrated Security=SSPI;" /
  -w "https://api.businesscentral.dynamics.com/v2.0/<TenantID>/<Environment>/ODataV4/Upload_LoadData?company=<Company>" /
  --tenantid <TenantID> --clientid <ClientID> /
  --clientsecret <Client Secret> /
  --sourcecompany <Source Company> /
  --mappingdatabase <Mappin
  --destinationcompany <Destination Company>  

After the interfaces have been defined using the above command, DataMigratePro has created the file settings.json.

{
  "SqlConnectionString": "Data Source=localhost;Initial Catalog=Demo Database NAV (6-0);Integrated Security=SSPI;",
  "SourceDatabase": "Demo Database NAV (6-0)",
  "SourceCompany": "<Source Company>",
  "DestinationCompany": "<Destination Company>",
  "TenantInfo": {
    "TenantId": "<TenantID>",
    "ClientId": "<ClientID>",
    "ClientSecret": "<Client Secret>"
  },
  "BlobMagicSignature": [ 2, 69, 125, 91 ],
  "EndpointUrl": "https://api.businesscentral.dynamics.com/v2.0/<TenantID>/<Environment>/ODataV4/Upload_LoadData?company=<Company>",
  "MappingDatabase": "Migration"
}

Transferring the mapping configuration

The following command is used to transfer the mapping configurations from the source system to the target system

DataMigratePro -t saveconfiguration

The following command is used to transfer the mapping configurations from the target system to the source system

DataMigratePro -t loadconfiguration

Transferring all master and setup data

As soon as the configuration tables have been added to the Navision database, the first transfer can be started.

DataMigratePro -t putalldata --automapping

The switch putalldata sends all table contents to Business Central whose category is Master data or Setup.

Transferring all posted documents and items

With putalldata, the data in the target table is also deleted before the data is transferred if the option Delete before Transfer has been set in the configuration for the respective table.

DataMigratePro -t putalldata --tablegroup "3,4" --automapping

Transferring changed data

If the change log is executed in Navision for tables, only the changes are sent to Business Central using the following command.

DataMigratePro -t putalldata --changesonly 1 --automapping

Transfer of individual tables

If data is to be generated from your own queries and sent to Business Central, a mapping file must first be created in addition to the actual command. Here is the command first.

DataMigratePro -t putdata -s 50149 \ -i "SELECT Feld1,Feld2 FROM Datenbank.dbo.MeineTabelle" \ -m mapping\MeineTabelle.mapping.json

A suitable mapping file could then look like this:

{
    "MeineTabelle": [
        {
            "FieldNo": 1,
            "FieldName": "Feld 1",
            "MappedName": "Feld1",
            "Validate": false
        },
        {
            "FieldNo": 2,
            "FieldName": "Feld 2",
            "MappedName": "Feld2",
            "Validate": false,
            "Format": "yyyy-MM-ddTHH:mm:ss"
        }
    ],
    "ValidateOnInsert": false,
    "ValidateOnModify": false,
    "ValidateOnDelete": false
}

Receiving data

If you want to find out what was last sent to Business Central, this information must first be queried using a command:

DataMigratePro -t getdata -s 50005 -n "BC Table Statistics" -m mapping/TableStatistics.mapping.json

The current structure of the tables in Business Central can also be read into the configuration database

DataMigratePro -t getdata -s 2000000058 -v "WHERE(Field1=1(1))" -n "BC Table" -m mapping\AllObjWithCaption.mapping.json
DataMigratePro -t getdata -s 2000000041 -n "BC Field" -m mapping\Field.mapping.json

The first command loads all available tables, while the second command completes the corresponding fields. The corresponding tables BC Table and BC Field are then updated.

Deleting data in Business Central

Complete contents or a filtered set of data records can be deleted via deletedata. In the following command, the data record of the Payment Terms table with the primary key LM is deleted.

DataMigratePro -t deletedata -s 3 -v "WHERE(Field1=1(LM)"

Execution of code units

The code unit 50001 is executed with the following command.

DataMigratePro -t execute -s 50001

Running DataMigratePro as a service

You can either run DataMigratePro as a permanent background service by installing it as a service.

sc create DataMigrateProService binPath= "\"C:\path\to\DataMigratePro.exe\" --service 8000" start= auto

Or you can initiate this temporarily on the command line

DataMigratePro --service 8000

The port number can be freely selected here. By calling the function SendDataToBusinessCentral in the supplied code unit BC Migration Manager with the single parameter RecordRef, exactly this data record is sent immediately but asynchronously to Business Central. The PC name and the port on which this service is running were previously specified in the local configuration in Navision.

Import of images and files in Business Central (not yet implemented)

The parameter -t importimages enables the automatic import of a directory structure and the upload of files to the Business Central system. These files are assigned to a Media or Mediaset field of a specific table. After the import, the respective field contains a GUID that refers to the Tenant Media table in which the actual files are stored.

Command syntax:

DataMigratePro -t importimages -s <TableNo> --field <FieldName> --sourcepath "<Pfad zur Verzeichnisstruktur>"

Parameter description:

  • -s <TableNo>: Specifies the target table in Business Central into which the images are imported.
  • --field <FieldName>: Specifies the target field in the table that is configured as Media or Mediaset.
  • --sourcepath "<Pfad zur Verzeichnisstruktur>": Specifies the source directory with the files to be imported.

Functionality:

  1. Scan directory: The specified source directory is scanned recursively to identify all supported file types. The respective directory name determines the primary key of the target table.
  2. Upload files: Each file is uploaded to the Tenant Media table as a blob. A new GUID is created for the file.
  3. Link to target table: The generated GUID is entered in the specified media or media set field of the target table.
  4. Storage in tenant media set: If a media set is used, the uploaded files are linked to a tenant media set.

Example:

DataMigratePro -t importimages -s 50000 --field "Produktbild" --sourcepath "C:\Produktbilder"
  • This command imports all images from C:\Produktbilder into the media field Produktbild of table 50000 (e.g. articles).
  • The images are saved in Tenant Media and the field values in the article table contain the corresponding GUIDs after import.

Prerequisites:

  • The target table must contain a media or media set field.
  • The Business Central instance must be configured for the use of media/mediaset fields.

Supported file formats:

  • Pictures: jpg, png, gif, bmp, tiff
  • Documents: pdf, txt, docx
Add a comment

Leave a Reply

Your email address will not be published. Required fields are marked *