web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

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

Shashi s Profile Picture Shashi s 1,203

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.


Filed under: AIF, Ax 2012, Dynamics Ax Tagged: AIF, AX2012, Dynamics Ax

This was originally posted here.

Comments

*This post is locked for comments