Category Archives: AIF

The CustCustomerService (External name CustomerService) can be used to create a customer in Ax through AIF.
When using the http adapter and consuming this service in a .Net Application, this is a tried and tested way to do it.
Notice the DirPartyTable assignment in the code. You do not need to specify the DirParty member, but that is where the customer name is held in Ax 2012

In the past posts I consumed a webservice InventItemService and created items in the Released products. This was used as a proof of what should happen when the data is sent to Ax. Part 2 looked at doing the same thing using the File system adapter. here we created an XML file, added the item id’s and then put the file in the folder, the batch did its magic and added the items to the Released Products list

A certain drawback to the that was we had to create the XML files manually, or use an external transformer to do it. AX 2012 has a new feature where we can add transformation Libraries in the form of Either XSLT or .Net libraries.

We will be taking the Inbound port created in Part 2 of this series, and add a transformation library, and instead of dropping an XML file into the inbound directory, we will drop a CSV file

Create Transformation Library

In Order to create a transformation library, we need to implement an interface found in Microsoft.Dynamics.IntegrationFramework
This DLL can be found in the directory: C:\Program Files\Microsoft Dynamics AX\60\Client\Bin\
More information about the Transformation can be found at: Walkthrough: Creating a .NET Assembly Transform [AX 2012]

What we need to do is create a Visual studio project, of a Class Library type

Create Class Library

Add a reference to the Microsoft.Dynamics.IntegrationFramework.Dll using the link above, and create a new class which implements the interface ITransform found in Microsoft.Dynamics.IntegrationFramework.Transform.ITransform

Then create a method which implements the method Transform. This method takes in 3 parameters

1. input (System.IO.Stream) : This is the input stream which is be the file itself
2. output (System.IO.Stream marked as out): This is the output stream that will be returned back to AX. We need to populate this stream
3. configuration (string): This is a custom configuration string that can be added to the port and can be used by the transformation. in this case we will not be using it.

Okay So we have a transformation Library, now we need to add code to read the data from the CSV file, which will be sent in the input stream as a parameter.
The CSV file we are going to add has 2 fields, the itemId and the name.
The Itemd also doubles up as the Product
The code should look like this, Its just reading a file and splitting the line contents.

So at this stage we have the data from our CSV file.We now need to somehow create an XML file similar to the one we created in Part 2. For this we will taking help of the XSD files we had take earlier and I will show you how to create a .Net class out of it. We will add these classes into the Library, and populate it. Serializing these classes will give us the XML file desired.

Creating Classes from XSD

What we did in the previous part was create an XML file that conforms to a certain XSD file. There are 3 XSD files in total that we used for creating the XML file. What we well do is create classes using the XSD files, populate them using the CSV file and serialize them.Upon serialization we will get the same output as the previous post.

In our Visual studio project we will first create 2 folders (to separate the objects generated into 2 different namespaces) ItemXSD and SharedXSD

Open the Visual studio command prompt and navigate to the directory where the XSD files were saved.

For the first instance, we need to create classes for the InventItemService. This XSD (item.xsd) is dependant on the SharedTypes.xsd We will specify both these XSD files and pass it to the XSD.exe command.

In the terminal type the following command:

xsd Item.xsd SharedTypes.xsd /classes /namespace:LooneyTrans.ItemXSD

This creates a file Item_SharedTypes.cs. Place this file in the folder ItemXSD of the project
Note: If you are creating the project in VB .Net, you can use the options in XSD.exe to output a vb file instead

Now create the code for the Envelope

xsd Message.xsd /classes /namespace:LooneyTrans.SharedXSD

Place the output file Message.cs in the folder SharedXSD of the project.

After doing so we should be able to access the object AxdEntity_InventTable, just like we did in Part 1 using web services.
We need to extend this one to adding an envelope which sets the Action for the document. The code should now look like this

We now need to compile the project and load the resulting DLL into AX.

Loading the Transformation Library

Going back to the Previous post where we created the Inbound port using the File System Adapter, we need to tell it to use our transformation library. To do so, first deactivate the port, and then set the Inbound Transforms to true.

Set Inbound transforms

From the inbound transform screen, we need to add the Library to the Main Transformation Library. Click the Manage Transformsand add the Library that we created and give it a name and description. Note that you need to set a class on the Manage transforms. This means that we can have more than one transform method in the class library and create a record for each of those.

Create Manage Transforms

We just added our transformation to the main repository and need to reference it in the Inbound transforms for this port

Create Inbound Transform

Notice that the configuration is a text field which can be loaded from a file. This is the text that is passed onto the Transform method created earlier.

After activating this, we should be ready to drop our file and start out batch job
So the File we are passing in look like this:

SS001,SS1ItemName
SS002,SS2ItemName

After dropping the File into the Inbound directory, the batch picks it up and pushes it into the Message Queue.

Item waiting in Queue

As you can see the message that has been created by the transformation Library is similar to the one we used in the Previous post.
When running the batch job again, this queue is processed and the items are pushed into the Released Product table

Result: Items SS001 and SS002 added to Released Products

This concludes the series of Importing a CSV file into AX using the File System Adapter. (*tears of joy rolling out now*)

The important part of the envelope is the Header where we define the Action. The action is the Service and the method we are targeting this document for. In this example, this document is targeted to the ItemService and the method is create. The ItemService is the External name of the InventItemService service we exposed for this adapter.

We need to drop this into the designated folder for the inbound and start the batch.

Create a Batch and add the following 4 classes as a batch task: AifGatewayReceiveService, AifGatewaySendService, AifInboundProcessingService, and AifOutboundProcessingService.

Set the Batch job to Waiting status, and wait for the batch to Run. You will want to make the batch run twice, the first time it runs the AifGateway adds the file to the Queue, the second time the batch runs, the AifInboundProcessing service will process the file and add the items to the Released products table.

The Queue can be seen at » System Administration > Periodic > Services and Application Integration Framework > Queue Manager

Also keep an eye on the Exceptions (found in the same menu) for any errors.

So after running the Batch for the first time, the Queue should be populated and be ready to be processed

Queue manager

Running the Batch again the items are added the “Released Products” list

Result: Items SS001 and SS002 added to Released Products

To wrap Part 2 up, we created an Inbound File system adapter and assigned the InventItemService.Create method to it. We then extracted our XSD, and with the help of an XML editor we created the file which we then placed into the folder for AX to upload.

Creating the XML file is cumbersome, and what I will like to do is to import a CSV file and use a .Net library to convert it to the XML file Dynamics AX wants.This new transformation in AX 2012 opens a world of possibilities to customize our input files and keep everything within AX and not have to use an external application to do that for us.