9 June 2016

Connectivity Studio and ICM Text Imports

Connectivity Studio and ICM text imports

Learn how to import ICM text files with only a field separator

As today’s tutorial shows, you can easily customize To-Increase Connectivity Studio for Microsoft Dynamics AX without changing our standard code. We are going to work through importing text files in ICM format with only a field separator.

Sometimes requests for ICM files are not easy to follow in setup, because the format has some limitations: It has only a field separator and no record separator. Normally, there is a line with multiple fields:

How to easily customize Connectivity Studio for Dynamics AX without changing the standard code

The ICM format is different. It contains one field per line. The field separator is a carriage return and linefeed.

How to import ICM text files with only a field separator

There are some restrictions to the ICM format:

  • It contains one header with multiple lines.
  • Each line and header always have the same number of fields.

We overcome these as follows.

Solution: Code additions and extending the text file base class with an XPO file

First define the test file and save it in a folder which can be accessed by a Connectivity Studio AOS user.

Code additions and extending the text file base class with an XPO file in Connectivity Studio

This format is not supported out-of-the-box. Therefore, we need some code additions that do not change the class in Connectivity Studio, but create a new one to be used. This also avoids future upgrade problems. The idea is to set up a document with only two records, one for the header and one for the lines. The steps are as follows:

  • Create a new document of the type Text and specify the field separator as shown below.

Code additions that create a new class in Connectivity Studio: Steps

  • Add a record and call it
    • Add field1, field2, field3 to it.
  • Add a record and call it Specify the header as parent.
    • Add field1, field2, field3 to it.

The form will look like the screen image below.

New form with field separator in Connectivity Studio

The problem is that you need to read the files differently. Now Connectivity Studio should read the first 3 fields and use that as header. Field 4, 5, and 6 are the first line, the next 3 fields are the second line and so on. That means that the way Connectivity Studio reads the fields should be changed. To accomplish this, you need to extend the base class for text files.

An XPO file is attached. It contains the class, which is described and which can be imported into the target environment. This is what the XPO file prompts Connectivity Studio to do:

  • When the headers are defined, it will always—based on the document definition—check the document and the number of fields to see how many lines should be read, given that each field is a line.
  • When the record is read, it will read the first set as header, all others as lines.

You can download the XPO file from Class_TstDocumentTextICM.xpo. After the download, you can import the XPO file into your development environment and select it as a custom handler in your document.

Import XPO file in Connectivity Studio

Now you're ready to run a test for the file. In the development pane, you can select the test option where you can specify a folder connection and a link to your file name. After running the test, you should see a result like illustrated below.

Run a test for XPO file in Connectivity Studio

Thanks for following along! I hope this tutorial helped you work with ICM text files in Connectivity Studio. If you need more information about our Business Integration Solutions, please get in touch. If you have any suggestions for improving our tutorials, please let us know, and we will be happy to incorporate them when we can.

Talk to our expert to know more about Connectivity Studio for Microsoft Dynamics AX

expert
Pieter de Jong
Pieter de Jong,
Pieter de Jong,
Technical Solution Architect

Also interesting