How to test Aif Document Service inside AX 2012

Hi Friends,

I am new to AX 2012. I have created one document service based on Production Order ( ProdTable and InventDim). Now I wanted to test this service from AOT suing X++ code. I know that it could be tested from Visual Studio 2012 using C #. I feel it’s complicated to test it from C#.

Anyone would like to share some sample code to do this test or any document or tutorial.



Hi Kaushik,

To test a document service in AIF in AX, you can either inbound an XML file or outbound an XML file. To send XML outbound, please check the sample code in Tables\CustInvoiceJour\sendElectronically.

Check these links

Hi Kaushik,

To test a document service in AIF in AX, you can either inbound an XML file or outbound an XML file. To send XML outbound, please check the sample code in Tables\CustInvoiceJour\sendElectronically.

Check these links

Hi Sushanth,

Thanks for your reply. Very useful link you provided. My requirement is for inbound document service. Like I will pass value Item, Qty and it will create production order in Prodtable.

I am not getting any way to test this from inside AX. It could be something like I will create one job and inside that job I will call that document service and it will create record.

Don’t know how to do that.



Hi Kaushik,

Not sure if it can be done internally in AX, but the usual way of doing a inbound using AIF document service is as below. These steps are more consice to give you some hint on process. You may need to read some white papers, technical documents before you begin.

  1. Create a XML with required data as per your schema and place this XML in appropriate inbound folder(

2.Write a job to inbound XML documents

// read the messages
new AifGateWayReceiveService().run();

// process the messages in queue
new AifInboundProcessingService().run();

Once if run the inbound job and if there are no errors, you can see the tables effected. But if there are any issues with the XML file or ports,etc, then an error log created in Exceptions.

Sushanth, you can simply call methods of your service class. For example, if you wanted to create a production pickling list, you would call ProdProdPickingListService.create().

Thanks Martin

Hi Sushanth,

Thanks for your suggestion. I have to look how I can create that XML file with data and which location I have to put that file. Anyway it’s great help.

Take care


Hi Kaushik,

You can test AIF services by writing simple job within AX as well. For example please find sample AX job for testing customer service in AX 2012 -

static void HM_CreateCustomer_Per(Args _args)

CustCustomerService customerService;// Customer Service class
CustCustomer customer; // Customer Document object
CustCustomer_CustTable custTable; // CustTable data object
CustCustomer_DirParty_DirPerson Per; // Person data object
AifEntityKeyList entityKeyList; // Entity key list
AccountNum accountNum;

// Create the service instance
customerService = CustCustomerService::construct();

// Create the Customer document object
customer = new CustCustomer();
customer.createCustTable(); // Create the CustTable list
custTable = customer.parmCustTable().addNew(); // Add CustTable instance to CustTable list

// Initialize the CustTable instance

// Create the Person
Per = new CustCustomer_DirParty_DirPerson();

// Initialize the Person instance
Per.parmName(‘Harish Tst Per102’);

// Create Customer
entityKeyList = customerService.create(customer);
accountNum = entityKeyList.getEntityKey(1).parmKeyDataMap().lookup(fieldnum(CustTable, accountnum));
info(strfmt(“Created customer: Account Number: %1.”, accountNum));


Hi Harish,

This is really great idea. Many many thanks for your suggestion.

I will try this.



Hi Harish,

I have created below code and right now getting error on financial dimension setup and it’s throwing error on “Document could not be created. Error Details: Update has been canceled”. Could you guide me where to look to solve this error?



prodOrder(Args _args)


ProductionOrderService prodService;

// Production Order Service class

ProductionOrder prodOrd;

// Production document object

ProductionOrder_ProdTable prodTable;

// prodTable data object

ProductionOrder_InventDim inventDim;

// InventDim data object

AifEntityKeyList entityKeyList;

// Entity key list


// Create the service instance

prodService = ProductionOrderService::construct();

// Create the Production Order document object

prodOrd =




// Create the ProdTable list

prodTable = prodOrd.parmProdTable().addNew();

// Add ProdTable instance to ProdTable list

// Initialize the ProdTable instance










//Start Setting up financial dimention

DimensionAttributeValue dimBu =



dimBu.parmName =



dimBu.parmValue =



DimensionAttributeValueSet valueSet =



valueSet.Values = DimensionAttributeValue[


] {dimBu};

prodTable.parmDefaultDimension = valueSet;

// End Setting up Financial dimension

// Create the InventDim

inventDim =



// Initialize the InventDim instance





// Create Production Order

entityKeyList = prodService.create(prodOrd);