Thursday, March 19, 2015

Invent Movement in AX 2012 R3 through AIF

Hi!

In this post I will show you the way for creating a Invent Movement Journal in Ax 2012 through AIF (FileSystem Adapter).

We do not have the standar service for Invent Movement journal but we can create a custom service or modify a existent service. I choosed the second one.

The InventProfitLossJournal Service has what it takes.














Now we will create the EndPoint



Now, we will select the option Service Operations







 And in the data polices form I selected the following fields


Now, check the schema out






We are going to create the XML File according to the schema


<?xml version="1.0" encoding="utf-8"?>
<Envelope xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message">
  <Header>
    <MessageId>{429AA009-09D4-45A9-BB2B-14DF0DFD3D93}</MessageId>
    <LogonAsUser>NETWORK\jarizmendi</LogonAsUser>
    <Company>ara</Company>    
    <Action>http://schemas.microsoft.com/dynamics/2008/01/services/ProfitLossJournalService/create</Action>   
    <RequestMessageId>
    </RequestMessageId>
  </Header>
  <Body>
    <MessageParts xmlns="http://schemas.microsoft.com/dynamics/2011/01/documents/Message">
        <ProfitLossJournal xmlns="http://schemas.microsoft.com/dynamics/2008/01/documents/ProfitLossJournal">
            <InventJournalTable class="entity">
                <AXHJRNO>AS400</AXHJRNO>
                <Description>Shitty Journal</Description>
                <JournalNameId>Entxcancel</JournalNameId>
                <JournalType>Movement</JournalType>               
                <InventJournalTrans class="entity">
                    <DefaultDimension xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />                   
                    <ItemId>MA451</ItemId>                                                       
                    <Qty>-3</Qty>
                    <TransDate>2013-05-28</TransDate>
                    <InventDim class="entity">
                        <InventBatchId>Surtido</InventBatchId>
                        <InventLocationId>002</InventLocationId>
                        <InventSiteId>Default</InventSiteId>
                        <WMSLocationId>General</WMSLocationId>
                    </InventDim>
            </InventJournalTrans>
            </InventJournalTable>
        </ProfitLossJournal>
    </MessageParts>
  </Body>
</Envelope>


Check the header

  <Header>
    <MessageId>{429AA009-09D4-45A9-BB2B-14DF0DFD3D93}</MessageId>
    <LogonAsUser>NETWORK\jarizmendi</LogonAsUser>
    <Company>ara</Company>    
    <Action>http://schemas.microsoft.com/dynamics/2008/01/services/ProfitLossJournalService/create</Action>   
    <RequestMessageId>
    </RequestMessageId>
  </Header>



 Action has the namespace of the service, the external name of the service and the action (Create).

The body has the same order than the Schema.

Also we need to change this class method



In the standar, the journal name is taken by the field ProfitLossJournalNameid, but we change this method and now the JournalNameId is taken by the XML File (Compile CIL).

In the XML File there are two tags that indicate this is a Journal  with a JournalNameId Entxcancel and its journalType is Movement 

Now we have to run this job

 
void jc()
{
    Args    args;
    AifGatewayReceiveService agrs = new AifGatewayReceiveService();
    AifInboundProcessingService aip = new AifInboundProcessingService();
    AifGatewaySendService agss = new AifGatewaySendService();
    AifOutboundProcessingService aop = new AifOutboundProcessingService();
    ;
    agrs.run();
    aip.run();
    agss.run();
    aop.run();



And the result is:



 

 And the lines




Field "itemGroupId" of "InventTable" is no longer.

As you know, changes in the 2012 version of Ax are many, for example because the tables, many fields have disappeared or are in other tables.

In the 2009 version of the "InventTable" table had the "ItemGroupId" field and get through very simple code was in the 2012 version this field is no longer in the "InventTable" and now must be obtained as follows:



The result is:



I hope it helps you.