How Do I Create Dynamic Text Files? (Magic xpi 4.5)
The Data Mapper utility lets you map data from various sources into various types of text files. To map the data into the text file, you need to create a template file using Magic xpi merge tags that define the data elements. The Data Mapper utility then uses these merge tags to map data from various Source types. This topic explains how to create dynamic text files in your project.
Note:
|
The template file can be in any format as long as the merge tags are stored as regular ASCII strings.
|
When you define a template file as the Destination in your Data Mapper utility, the merge mechanism scans the template file for merge tags. The scanned tags are then displayed in the Data Mapper screen’s Destination section. You can map to these tags from any Source. For example, you can map XML or Database fields to the tags.
When you run your project, the tags are replaced by values according to the Source mapping that you defined.
Here are some sample merge tags:
<!$MG_NAME> - this tag defines a tag name that is matched with a data element defined in the Data Mapper. You must replace NAME with a name for the tag. If a match is found when the Data Mapper scans the tag, the value replaces the tag.
<!$MGREPEAT> - this tag defines the beginning of a repeated area. The repeated area is duplicated and processed for each operation, thereby allowing for an unknown number of data rows. The tag is removed from the output.
<!$MGENDREPEAT> - this tag defines the end of a repeated area. The tag is removed from the output.
This example describes how to transfer database table content to a text file. The first step is to create the template file and the second is to configure your Data Mapper utility. Use the sample table below as an example.
Customer_ID
|
Order_ID
|
Product
|
Quantity
|
1
|
1
|
Chair
|
12
|
1
|
2
|
Table
|
12
|
Step 1: Creating the Template File
Create a text file with the following structure:
ID,Order_ID,Product,Quantity
-----------------------------
<!$MGREPEAT>
<!$MG_ID>,<!$MG_OrderID>,<!$MG_Product>,<!$MG_QTY>
<!$MGENDREPEAT>
Step 2: Configuring your Data Mapper utility
The steps below explain how to configure your Data Mapper utility:
-
Drag a Data Mapper utility to the flow area.
-
Double-click or right-click on the Data Mapper and click Configuration to open the Data Mapper window.
-
From the Toolbox's Mapper Schemas section, drag a Database type into the Source area of the Data Mapper window.
-
In the Database Definition drop-down list, select your database.
-
Click Wizard to open the Database Wizard.
-
In the Select Table screen under Available tables, select your example table or any other table, click Add, and then click Next to open the Select the Columns screen.
-
Click Add All to move the table’s columns to the Selected columns section and click b to open the Where Clause screen.
-
Click Next to go to the Wizard Result screen and then click Finish to close the wizard.
-
From the Toolbox's Mapper Schemas section, drag a Template type into the Destination area of the Data Mapper window.
-
In the Template Destination's Properties pane's Template File field, enter the location of the template file you created in Step 1.
-
In the Data Destination list box select File, enter the file’s location, and then click Save.
-
In the Data Mapper window, map the table columns in the Source to the appropriate Destination.
-
Save and run the project.