Consuming a AIF Document web service from external application.

Hi All,

Today i am going to explain you how can we integrate two applications where we need to use the data in Application 1 to create or update in Application 2.

Lets take for example:

App1: My AX

App2: Corporate AX

We need to create a new Purchase requisition in Corp AX when we confirm a PO in My AX.

For this we had provided a URI which was generated using the inbound port configured for Standard PurchReqImport service.

We need to consume the same in Visual studio:

Create a C# project in visual studio, create a service reference and provide the URI.

capture1

capture2

capture3

Build and deploy the C# project. Add to AOT.

capture4

Go and check in AOT.

capture5

Now write the code to consume the DLL after performing incremental CIL.

static void Job3(Args _args)

{

EAMPurchReq.PurchReq.PurchReqImportServiceClient    purchReqCilent;

// Create an instance of the document class.

EAMPurchReq.PurchReq.AxdPurchReqImport purchReqImport = new EAMPurchReq.PurchReq.AxdPurchReqImport();

#define.serviceType(‘EAMPurchReq.PurchReq.PurchReqImportServiceClient’)

ClrObject clientType;

PurchOrderedQty orderedQty;

PriceUnit       priceUnit;

UnitOfMeasureSymbol         priceunitofmeasure;

// Create instances of the entities that are used in the service and

// set the needed fields on those entities.

EAMPurchReq.PurchReq.AxdEntity_PurchReqTable   purchReqTable = new EAMPurchReq.PurchReq.AxdEntity_PurchReqTable();

EAMPurchReq.PurchReq.AxdEntity_PurchReqLine     purchReqLine = new EAMPurchReq.PurchReq.AxdEntity_PurchReqLine();

EAMPurchReq.PurchReq.AxdEntity_InventDim        inventDim = new EAMPurchReq.PurchReq.AxdEntity_InventDim();

EAMPurchReq.PurchReq.CallContext context = new EAMPurchReq.PurchReq.CallContext();

EAMPurchReq.PurchReq.AxdEntity_PurchReqLine [] arrayAssetPurchReqLine;

EAMPurchReq.PurchReq.AxdEntity_PurchReqTable [] arrayAssetPurchReqTable;

EAMPurchReq.PurchReq.AxdEntity_InventDim [] arrayAssetPurchReqInventDim;

//System.Object [] arrayAsset;

arrayAssetPurchReqLine = new EAMPurchReq.PurchReq.AxdEntity_PurchReqLine [1] ();

arrayAssetPurchReqTable = new EAMPurchReq.PurchReq.AxdEntity_PurchReqTable [1] ();

arrayAssetPurchReqInventDim = new EAMPurchReq.PurchReq.AxdEntity_InventDim [1] ();

purchReqTable.set_PurchReqId(“308”);

purchReqTable.set_PurchReqName(“Test”);

purchReqTable.set_TransDate(mkDate(17,10,2016));

purchReqTable.set_TransDateSpecified(true);

purchReqTable.set_RequiredDate(mkDate(17,10,2016));

purchReqTable.set_RequiredDateSpecified(true);

purchReqTable.set_AutoSubmitToWorkflowRequired(EAMPurchReq.PurchReq.AxdEnum_NoYes::No);

purchReqTable.set_RequisitionStatus(EAMPurchReq.PurchReq.AxdEnum_PurchReqRequisitionStatus::Draft);

purchReqTable.set_StatusToBeSaved(EAMPurchReq.PurchReq.AxdEnum_PurchReqCreationStatus::Draft);

purchReqTable.set_ExternalSourceID(“125”);

purchReqTable.set_ExternalSourceName(“Test”);

purchReqLine.set_ItemId(“851.2643/03”);

purchReqLine.set_BuyingLegalEntity(“EAM”);

purchReqLine.set_Requisitioner(“000002”);

orderedQty = 1;

purchReqLine.set_PurchQty(orderedQty);

purchReqLine.set_PurchQtySpecified(true);

purchReqLine.set_CurrencyCode(“AUD”);

purchReqLine.set_PurchPrice(1.0);

purchReqLine.set_PurchPriceSpecified(true);

priceunitofmeasure = “EA”;

purchReqLine.set_PurchUnitOfMeasure(priceunitofmeasure);

priceUnit = 1;

purchReqLine.set_PriceUnit(priceUnit);

purchReqLine.set_PriceUnitSpecified(true);

//inventDim.set_InventSiteId(“VIC”);

//inventDim.set_InventLocationId(“AMT01RENEW”);

// arrayAssetPurchReqInventDim.SetValue(inventDim,0);

// purchReqLine.set_InventDim(arrayAssetPurchReqInventDim);

arrayAssetPurchReqLine.SetValue(purchReqLine,0);

purchReqTable.set_PurchReqLine(arrayAssetPurchReqLine);

arrayAssetPurchReqTable.SetValue(purchReqTable,0);

purchReqImport.set_PurchReqTable(arrayAssetPurchReqTable);

context.set_Company(“EAM”);

try

{

//EntityKey[] returnFloc = client.create(context, TerminalGrpLocation);

clientType = CLRInterop::getType(#serviceType);

// Use the AifUtil class to create an instance of the service client object.

purchReqCilent = AifUtil::CreateServiceClient(clientType);

purchReqCilent.create(context, purchReqImport);

// The create method returns an EntityKey which contains the ID of the sales order.

//EntityKey returnedFloc = (EntityKey)returnFloc.GetValue(0);

//Console.WriteLine(“the TGL has been created of  ” + returnedFloc.KeyData[0].Value);

//Console.ReadLine();

}

catch

{

error(“error in the send”);

}

}

Purchase requisition gets created. I wrote a job to test it and was successful, You can write the same logic at Purchase order confirmation logic.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s