Scripting : Script Objects : Using a DJMessage Object with a Map
 
Share this page                  
Using a DJMessage Object with a Map
This example creates a process that uses a DJMessage object as a target to read data from an XML file and transforms the data in a map.
Creating Map Project Files
For this example you need to create a map and its associated data and configuration files.
To create map project files
1. In Design Manager, create a new project.
2. Create a source dataset that uses the ASCII connector and a target dataset that uses the XML-DMS connector.
3. Create a map that uses the artifacts.
4. Run the map to create an auto-generated run-time configuration that is saved in the project.
5. Validate and save the map.
Creating a Process with a DJMessage Object
For this example you declare the DJMessage objects by creating a global variable. You can also add a DIM statement to the Script step.
To create a process with a DJMessage object
1. In Design manager, create a new process.
2. From the Process window, select the View menu, then select Globals.
3. Add a new variable and select the DJMessage type.
4. Add a description, if desired.
5. Save the DJMessage object.
6. Save the process.
Intializing a DJMessage Object
The following procedure explains how to initialize a DJMessage object variable using a Script step. You can also set the variable in the Start step of a process using a Dim statement. See DJMessage Object Type.
To initialize a DJMessage object
1. Drag the Script step to the canvas.
2. Add the following to initialize the DJMessage object:
Set msgobject = new DJMessage msgobject
where msgobject is the name of the DJMessage object you created.
msgobject.body = FileRead("filename"), -3)
where filename is the name of the DJMessage file.
Note:  The -3 after the filename sets the encoding for file to UTF-8, the only acceptable encoding when using a DJMessage. This setting does not affect the encoding for the string or the message body.
3. Save the process
Adding a Transformation Step to a Process
In this procedure you add a Transformation step to a process and modify the map to specify the DJ Message object URI as the target of the transformation.
To add a transformation step to a process
1. Drag the Transformation step to the canvas.
2. Select the map from the drop-down list.
3. From the Dataset column, click the Edit button for the target dataset.
4. Click the Open button.
5. Click Start Session.
6. Replace the path to the XML file with a reference to the DJMessage object in the URI format: DJMessage:///msgobject, where msgobject is the name of the DJMessage object you created.
Note:  You cannot establish a connection to the data source when referencing a DJMessage object because the DataConnect Runtime Engine is unable to connect directly to the message object. You can save the dataset with the DJMessage URI reference or specify the DJMessage URL with a macro that points to the DJMessage object file. If you use a macro, you must change the macro value to the DJMessage URL in the run-time configuration. See DJMessage Object Type for more information.
7. Save the dataset and return to the Process window.
8. Save the process.
Linking Steps in a Process
1. Click the Link icon and add a link between the Start and Script steps.
2. Create a link between the Script and Transformation steps.
3. Create a link between the Transformation and Stop steps.
4. Validate and save the process.
Creating a Configuration and Running a Process
1. Run the process to create an auto-generated run-time configuration that is saved in the project.
2. Validate and run the process.