Friday 3 April 2015

Export Data with Outbound ports in AX 2012

Outbound ports are not related with web services or network at all (talking about WCF, bindings and endpoints). You can use it in order to retreive data from Dynamics AX and send the results to either a file or a message queue (MSMQ).


The following post will show a summary of the steps I followed in order to export customers in several XML files into a directory on the AOS server.






1)  Create an outbound port specifying "File system adapter" as adapter.
You can limit it to a specific company if you want
In the operations choose : CustCustomerService.read

This service operation will be used to read a customer from AX by specifying an account number.
The output result of the operation will be the customer itself.



2)  I create a new folder on the AOS side (in the example C:\AIFOutboundTest)
    Don't forget to give the correct write access rights for the user executing your AOS Service. The AOS will need write access to create the file.

3)  Specify the newly created folder in the URI of the outbound port and save the outbound port and activate it.

4)  Create a new job to post some customer in the AIF Queue :



static void sendCustomerOutbound(Args _args)
{

    AxdSendContext axdSendContext = AxdSendContext::construct();
    AifEntityKey aifEntityKey = AifEntityKey::construct();
    Map keyData;
    AifConstraintList aifConstraintList = new AifConstraintList();
    AifConstraint aifConstraint = new AifConstraint();

    CustTable       custTable;
    ;

    custTable = CustTable::find("US-001");

    keyData = SysDictTable::getKeyData(custTable);

    aifEntityKey.parmTableId(custTable.TableId);
    aifEntityKey.parmRecId(custTable.RecId);
    aifEntityKey.parmKeyDataMap(keyData);

    axdSendContext.parmXMLDocPurpose(XMLDocPurpose::Original);
    axdSendContext.parmSecurity(false);

    aifConstraint.parmType(AifConstraintType::NoConstraint) ;
    aifConstraintList.addConstraint(aifConstraint) ;

    AifSendService::submitDefault(
        classnum(CustCustomerService),
        aifEntityKey,
        aifConstraintList,
        AifSendMode::Async,
        axdSendContext.pack());

}

5)  Once this code is executed, a new record will be created in the AIF Queue manager.

You can reach the queue manager with the following path :
System Administration > Periodic > Services and Application Integration Framework > Queue manager

Status will be ready and you will see the document service operation involved.




6)  Now the instructions are created with correct parameters. You can either setup a batch system that will automatically execute the following method, or you can simply execute it manually.

static void runAIF()
{
    AifOutboundProcessingService outbound = new AifOutboundProcessingService();    outbound.run();
}

7)  Once this method has been executed, you will be able to see the resulting newly created AIF message (XML result). For this, use the following menu : Document Log and View message.




8)  Once the message has been created, we can execute the following method :

static void sendAIF()
{
    AifGatewaySendService        send     = new AifGatewaySendService();
    send.run();
}

9)  This operation will export the message to a physical XML file on the folder we specified in the outbound port.





No comments:

Post a Comment