I’ve just stumbled across a nice little ‘Easter Egg’ in the standard demo Hyper-V image: it’s all setup to import inbound customer purchase orders as sales orders in the AIF.
The setup is sitting there ready to go. Systems administration > Setup > Services and Application Integration Framework > Inbound ports:
So this Inbound port is going to process any valid .xml message file in the C:\AIF\In folder.
Those nice people at Microsoft have created that folder for you, and have even created a small, but perfectly formed .xml message as the file “Sample AIF SalesOrder-In R3.txt”:
Open that file and you’ll see:
Let’s save it as TEST1.xml, (you’ll have to change the ‘Save as type’ from ‘Text document (*.txt)’ to ‘All files’. Then you should be able to open the .xml file with Internet Explorer, which makes reading the XML slightly easier:
So you can see that this XML message structure is really simple. There’s a Header that tells Dynamics AX how to process the file; then there’s a group of sales order header (SalesTable) fields; and finally in this example there’s a single sales order line (SalesLine) group of fields (Item number, Sales quantity and Sales unit of measure).
Now when we run the job to import this message as a sales order the batch job (below) will delete the file – so if you’ve got an .xml file as above, move the original .txt file to another folder (I use the parent c:\AIF\ folder, but you can move/copy it to anywhere). Also the AIF will process .txt and .xml files so you can save the message you want to import in either format, whatever is simplest for you to view or edit.
And the last and final bit of setup has also been done. We need a recurring batch job to process the inbound and outbound AIF message. You’ll find the batch job at Systems administration > Inquires > Batch jobs > Batch jobs:
Click on ‘View tasks’ and you’ll see that it runs the four AIF processes, in sequence) – nice job Sara:
We’re going to run the job – but before we do I check the recurrence, and set the job to run just once (so that I’ve got some control over when and how often it runs):
Click OK to close the Recurrence form, then select the job and Functions > Change status:
Click on the Waiting status to set that, and the job will process after a minute or so:
Once it has run the status will set to ‘Ended’:
And we can go take a look at our sales order. To make it easier to find my orders I add the ‘Customer requisition’ field to the overview grid
Success! How easy was that?
So next you’ll want to play. Change the Customer requisition (SalesTable:PurchOrderFormNum) each time you create a new message to import. The standard AIF sales order import function detects a duplicate customer purchase order and creates another sales order of type Journal. You’re bright enough to have spotted the alignment between the .xml message fields and the Dynamics AX tables that are being populated. For instance if you want to add in the Sales origin your .XML will look like this:
Note. If you add new fields in a table group make sure you add them in alphabetical order. You’ll also have to de-activate the Inbound port, click on Data policies and ‘Enabled’ any field you want to import:
(or simply enable all fields).
Don’t forget to Activate the inbound port again once you’ve made your changes.
Obviously you make this a multi-line purchase order by simple copy’n’paste of all the SalesLine fields.
Keep a copy of the original example. Change one thing at a time, and if your message doesn’t create a sales order check Systems administration > Periodic > Services and Application Integration Framework > Exceptions. Remember that each time the batch job processes the inbound file it’ll delete it from the C;\AIF\In folder, so you’ll have to copy a freash file back in, then re-run the job. Hopefully the error message will make sense. In this example I’ve ‘deliberately’ forgotten to check that the sales origin code I added to the XML message actually exists in the main table.