How to: Add a new operation to AIF Document Service.

There are couple of document services in AX without all standard operation out of the box. A lot of time there is a need to get a sample of create operation. Usually in that situations we get a read (or find) operation to read data and then use this response as a basic template for create (or update) operation.

But what we can do in situations when there is only create method? (Our sample will be LedgerPurchaseInvoiceService)

First we need to update document service class. Open menu: Tools –> Development tools –> Application Integration Framework –> Update document service.

image

Select a proper class name – in our sample LedgerPurchaseInvoiceService. In form will be displayed service operations already existed in this service. We will check “find” operation and then also “regenerate data object classes”. A project with name “AxdPurchaseInvoice” will be generated.

Now, go to AOT and find Services –> LedgerPurchaseInvoiceService –> Operations. Right click and select “Add Operation”.

image

Mark our new operation and click OK. Save service and open AxdPurchaseInvoice project. Good practice is to add Services –> LedgerPurchaseInvoiceService to this project to keep all necessary on one place.

Locate in class AxdPurchaseInvoice method “findList”. Original one will look like:

public AifDocumentXml findList(AifQueryCriteria _queryCriteria, AifSchemaInfo _xsdInfo, AifEndpointActionPolicyInfo _actionPolicyInfo, AifConstraintListCollection _constraintListCollection, AifPropertyBag _aifPropertyBag) { ; throw error("@SYS94920"); }

We have to put some custom code. In our scenario this is acceptable:

public AifDocumentXml findList( AifQueryCriteria _queryCriteria, AifSchemaInfo _xsdInfo, AifEndpointActionPolicyInfo _actionPolicyInfo, AifConstraintListCollection _constraintListCollection, AifPropertyBag _aifPropertyBag) { AifDocumentXml xmlString; AxdBaseRead axdBaseRead; ; // Set AIF fault context this.setAifFaultContext(#DocumentOperation_Find); // Get send context properties this.unpackPropertyBag(_aifPropertyBag); // Construct the read class axdBaseRead = AxdBaseRead::construct(); axdBaseRead.parmAxdBase(this); axdBaseRead.parmQueryCriteria(_queryCriteria); if (_xsdInfo) { // Schema caching is not yet implemented in the reader axdBaseRead.parmFilterXSD(_xsdInfo.parmSchemaXml()); axdBaseRead.parmSchemaId(_xsdInfo.parmSchemaId()); } else { axdBaseRead.parmFilterXSD(''); } axdBaseRead.parmAifEndpointActionPolicyInfo(_actionPolicyInfo); axdBaseRead.parmConfigRecId(AifEndpointActionValueMap::find(_actionPolicyInfo.parmEndpointId(), _actionPolicyInfo.parmActionId()).RecId); // Find the document xmlString = axdBaseRead.findDocumentList(_constraintListCollection); return xmlString; }

If you are interesting how I know what I have to write there. Answer is simple I took a code from class named AxdBase method findList() – it perfectly fit our needs.

Now we need to set up this new operation service in AIF configuration. I am expecting that you already have AIF File System adapter setup and working. First make sure that your LergerPurchaseInvoiceService is enabled in AIF Services form. You need to click Refresh on this form too – to let AX know that new operation is prepared. Now open Endpoints form and select Action policies and click new – select LedgerPurchaseInvoiceService.find and be sure to enable it. Then you have to check Data policies form and enable fields which you want (need). You need to open this form at least once to generate XSD file.

image

And final step just to create simple call by job. We can use following code:

static void AxdSendPlusProcess(Args _args) { AxdSend axdSend; AifConstraintList aifConstraintList; AifConstraint aifConstraint; AifOutboundProcessingService aiop = new AifOutboundProcessingService(); AifGatewaySendService agss = new AifGatewaySendService(); ; axdSend = new AxdSend(); aifConstraintList = new AifConstraintList(); aifConstraint = new AifConstraint(); aifConstraint.parmType(AifConstraintType::NoConstraint); aifConstraintList.addConstraint(aifConstraint); axdSend.parmShowDocPurpose(false); axdSend.sendMultipleDocuments(classnum(LedgerPurchaseInvoice), classnum(LedgerPurchaseInvoiceService), AifSendMode::Sync, aifConstraintList); aiop.run(); agss.run(); }

Run the job, select Endpoint ID, Journal number and click OK. Xml file in outbound channel will be created.

image

–author: Karel Fischl
–editor: Karel Fischl
–date: 31/March/2011