Dynamics Ax 2012 – AIF Import CSV File – Part 2: Create Item from File adapter


This is part 2 of the series Import CSV file using AIF in AX 2012.

This is a continuation of Part 1, where we consumed the InventItemService.create to add items to the released products in Ax.

Part 1: Consume Web Service
Part 2: Create Item from File adapter
Part 3: Import CSV file with items Through AIF

Clean up: If you did try the previous post, the you would want to delete item SS001 from the release products.

Create inbound port

We will create a new Inbound port of type “File system adapter”

Inbound port setup

So now we need to create the document and then add it to the inbound folder

To create the file, we will need to First grab the schema file for inventItemService, and then wrap it around a Envelope, add a header to define what service this is calling.

Sounds like an awful lot indeed and hope i can make this look easier than what it is.

We need 3 schemas in total

To grab the InventItemService schema, open the AOT/Forms/AifService. This form lists all the available services

View Services

Open this form to reveal the schema:

Invent Item Service

We can now view our schema now and save it. Note the External name and Namespace as we will be using this later on in our Envelope

InventItemService schema

Save this File as InventItemService.xsd

You will see that within this schema is an import “SharedTypes.xsd”. To retrieve this file, click on the “View imported Schemas” from the above screen and save it as SharedTypes.xsd

Now we need the schema which has the Envelope defined. This is defined in a file called Message.xsd which can be found at the following location

C:\Program Files\Microsoft Dynamics AX\60\Server\bin\Application\Share\Include\

Now we can create our XML file to import using the AIF File system adapter

I have added 2 Items to the import SS001 and SS002. Both these items are existing products that have not yet been released.

The XML File will need to look like:

<?xml version="1.0"?>
<Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message">
  <Header>
    <MessageId>{46b5e41d-821b-4b20-831d-960c0fcceb1e}</MessageId>
    <Action>http://schemas.microsoft.com/dynamics/2008/01/services/ItemService/create</Action>
  </Header>
  <Body>
    <MessageParts>
      <Item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/Item">
        <SenderId xsi:nil="true" />
        <InventTable class="entity">
          <_DocumentHash xsi:nil="true" />
          <AltConfigId xsi:nil="true" />
          <AltInventColorId xsi:nil="true" />
          <AltInventSizeId xsi:nil="true" />
          <AltItemId xsi:nil="true" />
          <BatchNumGroupId xsi:nil="true" />
          <BOMCalcGroupId xsi:nil="true" />
          <BOMUnitId xsi:nil="true" />
          <CommissionGroupId xsi:nil="true" />
          <CostGroupId xsi:nil="true" />
          <DefaultDimension xsi:nil="true" />
          <Intracode xsi:nil="true" />
          <InventFiscalLIFOGroup xsi:nil="true" />
          <ItemBuyerGroupId xsi:nil="true" />
          <ItemId>SS001</ItemId>
          <ItemPriceToleranceGroupId xsi:nil="true" />
          <NameAlias>SS1ItemName</NameAlias>
          <OrigCountryRegionId xsi:nil="true" />
          <OrigCountyId xsi:nil="true" />
          <OrigStateId xsi:nil="true" />
          <PackagingGroupId xsi:nil="true" />
          <PBAInventItemGroupId xsi:nil="true" />
          <PrimaryVendorId xsi:nil="true" />
          <ProdGroupId xsi:nil="true" />
          <ProdPoolId xsi:nil="true" />
          <Product>SS001</Product>
          <projCategoryId xsi:nil="true" />
          <PropertyId xsi:nil="true" />
          <ReqGroupId xsi:nil="true" />
          <SerialNumGroupId xsi:nil="true" />
          <StandardConfigId xsi:nil="true" />
          <StandardInventColorId xsi:nil="true" />
          <StandardInventSizeId xsi:nil="true" />
          <WMSPalletTypeId xsi:nil="true" />
        </InventTable>
        <InventTable class="entity">
          <_DocumentHash xsi:nil="true" />
          <AltConfigId xsi:nil="true" />
          <AltInventColorId xsi:nil="true" />
          <AltInventSizeId xsi:nil="true" />
          <AltItemId xsi:nil="true" />
          <BatchNumGroupId xsi:nil="true" />
          <BOMCalcGroupId xsi:nil="true" />
          <BOMUnitId xsi:nil="true" />
          <CommissionGroupId xsi:nil="true" />
          <CostGroupId xsi:nil="true" />
          <DefaultDimension xsi:nil="true" />
          <Intracode xsi:nil="true" />
          <InventFiscalLIFOGroup xsi:nil="true" />
          <ItemBuyerGroupId xsi:nil="true" />
          <ItemId>SS002</ItemId>
          <ItemPriceToleranceGroupId xsi:nil="true" />
          <NameAlias>SS2ItemName</NameAlias>
          <OrigCountryRegionId xsi:nil="true" />
          <OrigCountyId xsi:nil="true" />
          <OrigStateId xsi:nil="true" />
          <PackagingGroupId xsi:nil="true" />
          <PBAInventItemGroupId xsi:nil="true" />
          <PrimaryVendorId xsi:nil="true" />
          <ProdGroupId xsi:nil="true" />
          <ProdPoolId xsi:nil="true" />
          <Product>SS002</Product>
          <projCategoryId xsi:nil="true" />
          <PropertyId xsi:nil="true" />
          <ReqGroupId xsi:nil="true" />
          <SerialNumGroupId xsi:nil="true" />
          <StandardConfigId xsi:nil="true" />
          <StandardInventColorId xsi:nil="true" />
          <StandardInventSizeId xsi:nil="true" />
          <WMSPalletTypeId xsi:nil="true" />
        </InventTable>
      </Item>
    </MessageParts>
  </Body>
</Envelope>

The Items have been added to the Body element of the Envelope

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.

AIF requires 4 batch tasks to be started for this, as defined in: Walkthrough: Exchanging documents by using the file system adapter [AX 2012]

Create a Batch and add the following 4 classes as a batch task: AifGatewayReceiveServiceAifGatewaySendServiceAifInboundProcessingService, 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.

Advertisements

11 thoughts on “Dynamics Ax 2012 – AIF Import CSV File – Part 2: Create Item from File adapter

  1. “Dynamics Ax 2012 – AIF Import CSV File –
    Part 2: Create Item from File adapter Shashi’s Ax.Net Space” ended up being a fantastic blog. If solely there was considerably more personal blogs similar to this particular one on the actual world wide web. Anyhow, thank you for your precious time, Mittie

    Like

  2. Hi,

    I am a bit confused with the three extracted .xsd files.
    What is the purpose of those extracted three .xsd files (Shared.xsd, Meessage.xsd, InventitemPrice.xsd )here?

    Regards,
    Rishi

    Like

    1. Hi Rishi. I am going to correct you first. The Files are Shared.xsd, Message.xsd and InventItemService.xsd (not price). The AIF service is build around receiving and sending XML files. XML files can be defined using XSD (XML Schema definition). So if your XML file doesnt conform to it, it will get rejected. I would suggest you Search online for more information regarding XSD and WCF to understand more about how AIF works.

      Like

      1. Thank you Shashi for your reply,
        I need to use AX’s table find method in my C# code. How do I achieve this as I need to find one value from other using find method. Somebody suggests me to write code in document service class instead. But it didn’t work or I might didn’t get the concept of putting code in document service class. Could you please help here ?

        Like

      2. Hi rishi. This is not a question for this topic. You can post this to the forums instead. Also have a look at https://blogs.msdn.microsoft.com/axsupport/2011/04/07/calling-the-find-method-on-an-aif-web-service/
        With AIF, you cant call table methods directly. You have a few operations you can do. For a more dynamics type, you can query the table. Maybe for what you want its a limitation. Or create your own AIF service or/and operation (See SysOperation Framework: https://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=29215 which can do what you want)

        Like

  3. Hi,

    I have to transform a CSV file to an xml file which will be used in my service.

    I followed the steps above

    The problem is that only string fields appear in xml file.

    Any idea ?

    Best Regard,

    Like

Leave a Reply / Comment

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s