Salesforce

How Do I Extract a Single Data Element from a Multi-Occurrence Compound? (Magic xpi 4.5)

« Go Back

Information

 
Created ByKnowledge Migration User
Approval Process StatusPublished
Objective
Description

How Do I Extract a Single Data Element from a Multi-Occurrence Compound? (Magic xpi 4.5)

Sometimes, you might need to extract a particular record from a multi-occurrence compound. The following example explains how to get the name of a specific account from a Source file.

Extracting a single data element from a multi-occurrence compound:

After you have dragged a Data Mapper into the Studio’s flow area, the first thing you need to do is to configure the Data Mapper’s Source properties, as follows:

  1. Double-click or right-click on the Data Mapper and click Configuration to open the Data Mapper window.

  2. From the Toolbox's Mapper Schemas section, drag an XML type into the Source area of the Data Mapper window.

  3. In the XML Source's Properties pane, select the required XSD file (in this case, Accounts.xsd).

  1. You need to define where you will take the data from, which, in this case, is a file called Accounts.xml. In the Source Type parameter, select File from the drop-down list.

  1. Open the Expression Editor with the button, and enter the following expression: EnvVal ('currentprojectdir')&'Data/Accounts.xml'

This expression tells the Source to look for a data file called Accounts.xml in the current project directory.

  1. Click OK to close the Expression Editor.

Once you have configured the Data Mapper’s Source properties, the next step is to configure the Destination properties, as follows:

  1. From the Toolbox's Mapper Schemas section, drag a Variable type into the Destination area of the Data Mapper window.

  2. In the Variable Destination's Properties pane, select the C.UserString context variable.

  1. Click OK to close the Destination Properties window.

Next, you need to map the Source data to the Destination data, as follows:

  1. In the Data Mapper window's Source pane, right-click on the Name node and select Connect. Then drag the mouse to the C.UserString node in the Destination pane, and click. These simple nodes, along with their respective parent compound nodes, will then be shown as connected in the Data Mapper window.

Our XML Source file contains three different accounts (as shown below). The phone numbers in the XML are not relevant for this example, so you can ignore them.

The next step is to create a condition on the Destination side to extract the name of the account whose ID value is 3:

  1. Right-click on the Instance compound node in the Destination pane and select Show Properties.

  2. In the node's Properties pane’s Condition parameter, click the button to open the Expression Editor.

  3. In the Expression Editor, click the button and select the correct path for the ID node from the list.

  1. Click OK to close the Expression Editor.

  2. In the flow area, set a breakpoint, and then debug the flow by right-clicking on the flow in the Solution Explorer and selecting Debug.

  3. Run your project by clicking the Run button on the toolbar.

  4. Click the Context View button on the toolbar to open the Context View window.

  5. Here, select the Context Variable tab and look in the Name column for the C.UserString variable. Remember that you previously selected this variable in the Destination Properties dialog box to hold the results data. This variable will display the name of the account that you wanted to extract from the Source file in its Value column. In this example, the account’s name is Account3.

Reference
Attachment 
Attachment