Send outbound documents with AIF in AX 2012 - Walkthrough

In this post, I am going to perform a walk-through of sending customer data out of AX 2012 system. The mode is asynchronous. The output is an XML file with customer data in it.

Pre-requisites

  1. A working AX 2012 system with AIF configured. I am using MS VM for R3 CU9.
  2. A shared folder to write files. The AX user should have write access to the folder.
  3. Basic knowledge of AIF and X++ coding.
Process

Setup outbound port – 
Go to System administration > Setup > Services and application integration framework > Outbound ports
Create a new port – Customer, enter some description. Choose ‘File system adapter’. In URI, provide path of your shared folder. Make sure that this is an UNC path not local drives. Click configure button and select ‘Choose default owner for Administrators group’ check-box, and select the AX user name from the drop-down. The domain user which is attached to this AX user should have the ‘write’ access to the shared folder path.



Select service operation – CustCustomerService.read


Tip – If all the service operations are not visible in the ‘Remaining service operations’ list. Go to AOT > Forms > AifService > Click ‘Refresh’ button. This may take 5-10 minutes to refresh services and schemas. Then again open the outbound ports. The operations will be refreshed now.

Set data policy – Tick the ‘Customize documents’ check-box and click ‘Data policies’ button. Enable the fields which you want to send to the XML. Below is the list of fields I choose.


In Troubleshooting section, select ‘All document versions’ in logging mode and tick ‘Include exceptions in fault’. These will help you identify issues later on.

Click on ‘Activate’ to activate the port.


You should get a message that port is deployed successfully.

Setup AIF batch job -

     Second step is to start the batch job which maintains the outbound queue and process the requests from queue. In MS VM a batch job named ‘AIF processing’ is already there which takes care of both inbound and outbound AIF message processing. Otherwise a batch job can be manually created.

Make sure that you have at least on server set as batch server. Go to System Administration > Setup > System > Server configuration. Check that at least one of available server is marked as batch server. The batch schedule should be setup correctly so that the batch runs. Lastly the batch group (which we are going to use in batch job) should be selected.


Once you make sure that above configuration is set, create your own batch job manually (System administration > Inquiries > Batch jobs). In the batch tasks do the following setup


Only the highlighted records are needed for outbound. The AifGatewaySendService should run after the AifOutbounndProcessingService task.

In the end DO NOT FORGET to set the recurrence of the batch job to keep running periodically and set the status of the batch job to ‘Waiting’.



Setup push mechanism -

In AX, there are multiple document for which ‘Send electronically’ functionality is available out-of-the-box. For customer we have to build it. Open AOT and create a new class which extends AxdSend class. In the main method of this class put the below code. (Port name cab be parameterized or not included at all)


Create a menu item which points to this class and add this menu item to the General tab in action pane of Customer and customer list forms. (I assume you have enough coding experience to do this task) Don’t forget to add AX security artifacts for new menu items.

Send the data out -

By now we have all the components needed to send the XML file out. Open the customer form (AR > Common > Customers > All customers) Go to General tab in action pane (or wherever you have put your menu item) and click ‘Send electronically’ (the new menu button).



In the ‘Send document’ form, select the correct outbound port and customers which need to be send in the file and click OK.

Check the results -

After the process, a record is created in the AIF processing queue which can be viewed by going to System administration > Periodic > Services and application integration framework > Queue manager.


Once the batch job will pick this record up, this record will be deleted and another record will be created in history. It can be viewed from System administration > Periodic > Services and application integration framework >History.



In case any error occurs, record(s) will be created in Exceptions (System administration > Periodic > Services and application integration framework > Exceptions)

Once it is processed successfully, an XML is created at shared location.


Below is the XML which I received.

https://drive.google.com/file/d/0ByzwyaPDBPLqdXZETHhETTFQcXM/view?usp=sharing

Comments

  1. Why did the created XML message take the "find" as action, although you included both read and find operations in the port service operations. can i control the selected action or even the schema by x++ code?

    ReplyDelete

Post a Comment

Popular Posts