Salesforce

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

« 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 3.x)

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. In the Data Mapper Configuration dialog box, click Configuration.

  2. In the Source/Destination Management window, click New on the Source side. Set the Source’s Type as XML.

  3. Click Properties on the Source side.

  4. In the Source Properties window’s XSD File parameter, click the button and 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 Data Source 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, followed by the Source Properties window.

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

  1. In the Source/Destination Management window, click New on the Destination side. Set the Destination’s Type as Variables.

  2. Click Properties on the Destination side.

  3. In the Destination Properties window, 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 Source/Destination Management window, click Map to open the Data Mapper window.

  2. In the 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 (as shown below).

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 Properties.

  2. In the Node Properties dialog box, select the General tab.

  3. In the Execute Condition section’s Condition parameter, click the button to open 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, followed by the Destination’s Node Properties window, the Data Mapper window, and the Data Mapper Configuration screens.

  2. Set a breakpoint, and then debug the flow by right-clicking on the flow in the Navigation pane and selecting Debug.

  3. Run your project by clicking the Run/Continue Project 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.
    As you can see below, 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