Importing Leads and Contacts

You can find a very good description on our team blog (EMEA Dynamics AX Support) how to import leads and contact Xml files with Dynamics Ax 2009 here. The problem you will be faced by using this is, that you can’t import data with non Ascii characters, which might cause some difficulties. The reason for that is the way how the Xml files is proceeded during the transformation process.

Ax creates first a copy of the Xml file and the Xslt File in the temp directory of the AOS which is by default:

C:\Program Files\Microsoft Dynamics AX\50\Application\appl\DynamicsAx1\tmp\

Unfortunately this is done by reading out the Xml file into a container and then creating a new Xml file by using the method:

SysImportUtil/createFileFromContainer

Unfortunately because it is using the AsciiIo to create the file. Since this class is intended to encode the content of the container into Ascii, it is  incompatible with Xml files. The sample files are using Xml files encoded in Utf-8 which is some kind of an extension to Ascii and this is the reason why you can’t use this import for non Ascii characters:

[..] AsciiIO supports only ANSI code page (ACP) characters.

But you can fix this by replacing the AsciiIo by the TextIo class. Msdn describes it as follow:

TextIO replaces AsciiIO to provide support for non-ANSI code page file I/O. The TextIO constructor has an additional optional parameter to set the code page of the file.

This is exactly what we need. The most common codepages are:

  • 0 - CP_ACP; the ANSI code page
  • 437 - OEM code page 437
  • 850 - Code page 850
  • 1200 - UTF-16LE (default value)
  • 1201 - UTF-16BE
  • 65001 - UTF-8
  • 54936: GB-18030

So, if you want to use the Xml-files from the example without any modification you need to change the codepage to 65001, but it is easier to change the Xml-file to Utf-16. This can be done easily by using Visual Studio:

Just open the Xml-file, change the Utf-8 to Utf-16 and safe the changes. Why not using the notepad ?

Visual Studio reads out the Xml encoding information:

 <?xml version="1.0" encoding="utf-16"?>

and adds the required file signature to that file (called BOM). These information can be consulted with the Visual Studio binary editor (File/Open/File/<select Xml-file>/Open as/binary editor): “EF BB BF” for Utf-8 and “FF FE” for Utf-16.

So in order to import data with non-Ascii data, you have to:

  1. replace the AsciiIo class by TextIo
  2. import Utf-16 encoded Xml data.