Walkthrough: Configure XML/File Data Export via AIF in AX 2012
31. January 2018 2 Comments
This is an example how to export the LedgerJournalTable + LedgerJournalTrans records as XML via AIF
Create a Query
- Create a new query and name it AxdLedgerJournal.
- Place the LedgerJournalTable as main Datasource
- Set the Fields Property Dynamic to Yes
- Add the LedgerJournalTrans as child data source
- Set the Fields property Dynamic of the LedgerJournalTrans data source to Yes
- Set the Relation property of the LedgerJournalTrans data source to Yes
- Set the Fetch Mode property of the LedgerJournalTrans data source to 1:n
- Set the Join Mode property of the LedgerJournalTrans data source to Outer Join
Use the AIF Document Wizard to generate the service classes
- In the menu bar go to Tools > Application Integration Framework > Create document service
- Provide the AxdLedgerJournal query as source query for the document service
- Select the options to generate the Read and Find methods
- Select the option to generate the AxBC classes
- Let the wizard generate the software artifacts for you
Fine tune the generated code
- Go to the private projects and open the newly generated project
- Compile the project
- If the cache() methods don’t compile delete them
- Review the open tasks and provide meaningful labels
Configure the Batch Jobs
- In AX go to System Administration > Inquires > Batch Jobs > Batch Jobs
- Create a new Batch Job and go to “View Task”
- Add four task and choose the following classes
- AifGatewayReceiveService
- AifGatewaySendService
- AifInboundProcessingService
AifOutboundProcessingService - Close the Task window and set the Recurrence of the Batch Job to run e.g. all 5 minutes
Configure the File System Adapter
- In AX go to System Administration > Setup > Services and Application Integration Famework > Outbound Ports
- Create a new Outbound Port
- Select the FileSystemAdapter as Adapter
- Provide a target location where to place the files e.g. a share with write permissions for the AOS account
- Open the Service Operation Dialog and add the LedgerJournalService.read method
- Activate the Port
Add a send method
On the LedgerJournalTable add the following method
server void sendElectronically(XMLDocPurpose _xmlDocPurpose,
AifSendMode _aifSendMode = AifSendMode::Async)
{
AxdSendContext axdSendContext = AxdSendContext::construct();
AifEntityKey aifEntityKey = AifEntityKey::construct();
Map keyData;
AifConstraint aifConstraint = new AifConstraint() ;
AifConstraintList aifConstraintList = new AifConstraintList();
;
keyData = SysDictTable::getKeyData(this);aifEntityKey.parmTableId(this.TableId);
aifEntityKey.parmRecId(this.RecId);
aifEntityKey.parmKeyDataMap(keyData);axdSendContext.parmXMLDocPurpose(_xmlDocPurpose);
axdSendContext.parmSecurity(false);aifConstraint.parmType(AifConstraintType::NoConstraint);
aifConstraint.parmId(this.JournalNum);
aifConstraintList.addConstraint(aifConstraint);AifSendService::submitDefault(
classNum(LedgerJournalService),
aifEntityKey,
aifConstraintList,
_aifSendMode,
axdSendContext.pack());
}
Test the export
Create a job and use the following code to test the export
static void JobTestAifExport(Args _args)
{
LedgerJournalTable journal;
;
journal = ledgerJournalTable::find("00001");
journal.sendElectronically(XMLDocPurpose::Original);
}
In AX got to System Administration > Periodic > Services and Application Integration > Queue Manager. You will find a record for the LedgerJournal export. The Batch Job will first create an XML Document and in a second step perform the export to the file system.
thanks for this info.
How does AX send the xml from the queue manager to another system (3rd party software)?