Connectivity Studio and ICM Text Imports
Table of contents
Learn how to import ICM text files with only a field separator
As today’s tutorial shows, you can easily customize STAEDEAN 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:
The ICM format is different. It contains one field per line. The field separator is a carriage return and linefeed.
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.
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.
- 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.
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.
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.
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.