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.

Thanks,

Kaushik

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 http://technet.microsoft.com/EN-US/library/cc593511.aspx

http://community.dynamics.com/product/ax/axtechnical/b/dynamicsaxposed/archive/2012/03/29/how-to-develop-inbound-web-service-in-ax-2012.aspx

http://daxdilip.blogspot.in/2010/05/aif-links.html

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 http://technet.microsoft.com/EN-US/library/cc593511.aspx

http://daxdilip.blogspot.in/2010/05/aif-links.html

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.

Thanks,

Kaushik

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.http://dynamicsuser.net/forums/p/43423/219837.aspx

  1. Create a XML with required data as per your schema and place this XML in appropriate inbound folder( http://technet.microsoft.com/en-us/library/bb530212.aspx)

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

Kaushik

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
custTable.parmCustGroup(‘STUDENT’);
custTable.parmCurrency(‘USD’);

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

// Initialize the Person instance
Per.parmName(‘Harish Tst Per102’);
Per.parmLanguageId(‘en-us’);
custTable.createDirParty().add(Per);

// 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.

Thanks,

Kaushik

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?

static

void

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 =

new

ProductionOrder();

prodOrd.createProdTable();

// Create the ProdTable list

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

// Add ProdTable instance to ProdTable list

// Initialize the ProdTable instance

prodTable.parmItemId(

‘D0005’

);

prodTable.parmProdId(

‘P000175’

);

prodTable.parmQtySched(

1

);

//Start Setting up financial dimention

DimensionAttributeValue dimBu =

new

DimensionAttributeValue();

dimBu.parmName =

“BusinessUnit”

;

dimBu.parmValue =

‘022’

;

DimensionAttributeValueSet valueSet =

new

DimensionAttributeValueSet();

valueSet.Values = DimensionAttributeValue[

1

] {dimBu};

prodTable.parmDefaultDimension = valueSet;

// End Setting up Financial dimension

// Create the InventDim

inventDim =

new

ProductionOrder_InventDim();

// Initialize the InventDim instance

inventDim.parmInventSiteId(

‘1’

);

prodTable.createInventDim().add(inventDim);

// Create Production Order

entityKeyList = prodService.create(prodOrd);

}