How
to import and export data in XML format using AIF framework?
This is the second part of the article about
import and export data in XML format.In the first post we have shown how to import and export data in XML format using Axd classes and it was mostly oriented to X++ developers.
In this post, we
will use data generated in the first post (AxBc and Axd classes) and will
explain how to import and export data in XML format, but using Application
Integration Framework (AIF) features and batch framework. This article is
mostly oriented to end-users.
Setup part:Setup part consists of two parts: AIF setup and Batch framework setup.
AIF setup:
Before starting
AIF setup, please import the xpo file with all required objects from here. Even if you have generated these objects before as a
part of the first article, you still need to import it because some objects
were slightly modified in order to implement Send functionality which will be
used in this article.
The path to the AIF setup forms is: Basic
> Setup > Application Integration FrameworkFigure 0. AIF setup forms location.
1) Open Local
endpoints form and create a new local endpoint for the company where you want
to import data to or to export data from. In our case, it is company DAT.
Figure 1. Local endpoints form
2) Open Transport
adapters form and create a new transport adapter for the file system. Set
Direction field to "Receive or Send" and select Active checkbox.
Figure 2. Transport adapters form
3) Open Channels
form and create two new channels - Outbound and Inbound. The channes simply
specify where the files should be taken from or put in.
At first, create
an outbound channel and then create an inbound one and assign the outbound
channel to it. For the outbound channel, create a folder C:\AIF\Outbound and
for the inbound one - C:\AIF\Inbound.
kFigure 3. 1. A new outbound channel
Figure 3.2. A new inbound channel with the assigned to it outbound one.
4) Open Actions
form and click "Scan and register" button in order to find new
documents and generate new actions for them. In our case, the system will be
looking for AxdMyTable document and will be generating Create, CreateList,
FindEntityKeyList, FindList, Read and ReadList actions for that document. For
all these actions, we need to manually select "Enabled" checkbox.
Figure 4.1. Actions form before new actions were generated.
Figure 4.2. Actions form - searching AOT for new documents
Figure 4.3. Actions form - new actions CreateMyTable and CreateListMyTable for AxdMyTable document.
Figure 4.4.
Actions form - new actions FindEntityKeyListMyTable and FindListMyTable for
AxdMyTable document.
Figure 4.5.
Actions form - new actions ReadMyTable and ReadListMyTable for AxdMyTable
document.
5) Open Endpoints
form and create a new endpoint. The endpoint is used to define rules for import
and export of documents (where to export, who can export, which table fields to
export or to import, etc.).
Figure 5.1. Endpoints form, Overview tab
Figure 5.2. Endpoints form, General tab
Figure 5.3. Endpoints form, Constraints tab
Figure 5.4. Endpoints form, Users tab
6) In the
Endpoints form, click Action policies button. In the Endpoint Action Policies
form, you need to add all 6 actions generated in the Actions form in order to
be able to apply these actions for the AxdMyTable document. For each action,
you need to set the Status field to "Enabled" and Logging Mode to
"Log All".
Figure 6.1. Endpoint Action Policies form - action selection
Figure 6.2. Endpoint Action Policies form - all actions added
7) The last step
of the AIF setup part is to enable fields that can be imported or exported for
each action. For that, select an action and click "Data policies"
button and enable following four fields: DocPurpose, MyFieldInt, MyFieldStr,
Sender as shown on the picture below. Repeat it for each action.
Figure 7. Data policies selection for createListMyTable action.
Batch framework setup:
8) The path to the Batch setup forms is: Basic > Setup > Application Integration Framework.
Figure 8. Batch setup forms location.
9) Open Batch groups form and create a new batch group.
Figure 9. Batch group form with a new batch group 'AIF'.
10) Open Journal
types form and create a new batch journal type. On the General tab, add four
following classes that will be run by batch framework in order to import or
export data: AifGatewayReceiveService, AifInboundProcessingService,
AifOutboundProcessingService, AifGatewaySendService. The sequence in which you
add them is not important at this point.
Figure 10.1. Batch journal type form.
Figure 10.2. AIF RunBaseBatch based classes added to the batch journal type.
11) Open Journal
names form and create a new journal name. Give it a name 'AIF' and in the
Journal type field, select 'AIF' journal type created in the previous step.
Figure 11. Batch journal name form.
12) In the Batch
journal name form, click Jobs button. In the Batch journal line form, click
Ctrl+N and select a class name from the lookup form. Repeat it for each class
name. After all four classes are added, sort them using Up and Down buttons so
that they are listed in the following order:
1.
AifGatewayReceiveService
2.
AifInboundProcessingService
3.
AifOutboundProcessingService
4.
AifGatewaySendService
Figure 12.1. Batch journal line form - class name selection.
Figure 12.2. Batch journal line form - classes are in the correct positions.
That's it with the setup part.
Let's go to execution phase.
Execution part:
1) Import from XML file.
1.1) Copy the
createListMyTable.xml file to the C:\AIF\Inbound folder.
1.2) Go to Basic
> Periodic > Batch and open Batch journal execution form. Specify a
journal name, a batch group and recurrence if necessary, and select the batch
processing checkbox and click OK button.
Figure 1.1. Batch execution forms
Figure 1.2. Batch journal execution form - the journal name selection
Figure 1.3. Batch journal execution form - the batch processing, the batch group and the recurrence selection.
1.3) Open Processing form, select 'AIF' batch group and click OK.
Figure 1.4. Batch processing form
Now the
createListMyTable.xml file should be imported into MyTable table and if you
open the form MyTable form (it is a part of the xpo project imported in the
beginning of AIF setup) you should be able to see two records:
Figure 1.5. Two records imported from the XML file
2) Export into XML file
2.1) Open MyTable
form (select the form in AOT and click Open icon), select the first record and
click Send electronically button. Now the job is added to the gateway queue and
as soon as you run the batch jobs this document will be exported.
2.2) Repeat the steps 1.2 and 1.3 from the
Import part. This will run the batch jobs.
2.3) Now the first
record from the MyTable table should have been exported into XML file and you
should be able to find it in C:\AIF\Outbound folder.
Figure 1.6. The exported 20083624_213604_2113008_00001.xml file.
That's all.
A hint:
If you have a
problem and don't know why data was not imported or exported, look at the Basic
> Periodic > Application Integration Framework > Exceptions form. This
form has a log of all errors occurred during AIF processes and an explanation
why they occurred.
No comments:
Post a Comment