// This module is included in the following assemblies:
// as_mapping-data.adoc

[id='separate-one-source-field-into-multiple-target-fields_{context}']
= Separating one source field into multiple target fields

In a data mapper step, you can separate a compound source field into multiple
target fields. For  example, map the `Name` field to the `FirstName` and
 `LastName` fields.

.Prerequisite
For the source field, you must know what type of content is in each
part of this compound field, the order and index of each part of the content, 
and the separator between parts, such as a space or comma. See
link:{LinkSyndesisIntegrationGuide}#example-missing-unwanted-data_map[Example of missing or unwanted data]. 

.Procedure

. In the *Sources* panel, click the field whose content you want to separate and then click image:images/integrating-applications/create-mapping-icon.png[the Create new mapping icon]. 
. In the *Mapping Details* panel, from the *Target* drop-down list, select the data fields that you want to map to.
+
When you are done selecting target fields, you should see lines from the 
source field to each of the target fields that you selected. 
+
At the top of the *Mapping Details* panel, the data mapper displays 
*Split* to indicate that execution of the mapping splits the source 
field value and maps it to multiple target fields. 
+
Under *Targets*, there is an entry for each target field that 
you selected.

. In the *Mapping Details* panel, configure the mapping as follows: 
+
.. Under *Sources*, in the *Delimiter* field, accept or select the 
character in the source field that indicates where to separate 
the source field values. The default is a space.
.. Optionally, click image:images/integrating-applications/transformation-icon.png[the Transformation icon] to apply a transformation 
to the source field value before it gets mapped to the target field. 
.. Under *Targets*, check the order of the entries for the target 
fields that you selected. The entries must be in the same order 
as the corresponding content in the compound source field. 
It does not matter whether you did not specify a target field 
for one or more parts of the content in the source field.
+
If the entries are not in the correct order, change the index number for the field entries to achieve the same order.
+
If you mapped each part of the compound source field to a target 
field, then skip to the next step.
.. If the source field contains data that you do not need, 
then in the *Mapping Details* panel, edit the index of each 
target field that does not already have the same index as the 
corresponding data in the source field. Each target field entry 
must have the same index that the corresponding data has 
in the source field. The data mapper automatically adds 
padding fields as needed to indicate unwanted data.
+
See the example at the end of this procedure. 
.. Optionally, click image:images/integrating-applications/transformation-icon.png[the Transformation icon] to map the content into 
the target field and then apply a transformation as described in link:{LinkSyndesisIntegrationGuide}#transform-target-data_map[Transforming source or target data]. 

. Optionally, preview the data mapping result: 
.. Click image:images/integrating-applications/preview-mapping-icon.png[the Show/Hide Preview Mapping icon] to display a text input field on the source
field and read-only result fields on each target field. 
.. In the source field's data input field, type a sample value. Be sure to enter
the separator character between the parts of the field. The mapping result appears in the read-only fields for the target fields.
+
If you reorder the target fields or add a transformation to a target field 
then the result fields on the target fields reflect this. If the data mapper
detects any errors, it displays informative messages at the top of the 
*Mapping Details* panel. 

.. Hide the preview fields by clicking image:images/integrating-applications/preview-mapping-icon.png[the Show/Hide Preview Mapping icon] again.
+
If you redisplay the preview fields, any data that you entered in them is 
still there and it remains there until you exit the data mapper. 

. To confirm that the mapping is correctly defined, click
image:images/tutorials/grid.png[the Mapping Table icon] to display the mappings defined in
this step. A mapping that separates the value of a source field into
multiple target fields looks like this:
image:images/integrating-applications/SeparateMapping.png[Separate Fields Mapping]. 
+
You can also preview mapping results in this view. Click 
image:images/integrating-applications/preview-mapping-icon.png[the Show/Hide Preview Mapping icon], and then type text as described in the previous step.
Preview fields appear for only the selected mapping. Click another
mapping in the table to view preview fields for it. 

.Example of separating one field into multiple fields

Suppose that the source data contains one address field and it uses 
commas to separate the content parts, for example:

----
77 Hill Street, Brooklyn, New York, United States, 12345, 6789
----

In an address field, the parts of the content have these indexes: 

[options="header"]
[cols="2,1"]
|===
|Content
|Index

|Number and street
|1

|City
|2

|State
|3

|Country
|4

|Zip code
|5

|Zip+4
|6

|===

Now suppose that the target data has four fields for an address:

----
number-and-street
city
state
zip
----

To define the mapping, you do the following: 

* Select the source field and then click image:images/integrating-applications/create-mapping-icon.png[the Create new mapping icon].
* In the *Mapping Details* panel, in the *Sources* section, 
select the delimiter, which is a comma in this example. 
* Select the four target fields. 

After you do this, in the *Mapping Details* panel under *Targets*, 
there is an entry for each target field that you selected, for example: 

image:images/integrating-applications/Example-Adding-Padding-Mapping.png[Example of initial entries]. 

The data mapper displays the target entries in the order in which 
they appear in the data mapper, which is alphabetical. You need to 
change this order so that it mirrors the order in the source field. 
In this example, the source field contains the `number-and-street` 
content before the `city` content. To correct the order of the 
target entries, edit the `city` index field to be `2`. 
The result looks like this: 

image:images/integrating-applications/Example-Adding-Padding-Mapping-2.png[Example or reordered entries]. 

In the target field entries, the index numbers indicate the part of 
the source field that will be mapped to this target field. One of 
the index values needs to change to achieve the correct target field value.
Consider each target field: 

* `number-and-street` — In the source field, the number and street 
content has an index of 1.  It is correct to map the index 1 source 
to the `number-and-street` target field. No changes are needed 
in this target entry. 
* `city`  — In the source field, the city
content has an index of 2. This target entry is also correct as it is. 
* `state`  — In the source field, the state content has an index of 3. 
This target entry is also correct as it is. 
* `zip`  — In the source field, the zip code content has an index of 5. 
The target field entry index of 4 is wrong. If you do not change it, during
execution, the country part of the source field gets mapped to the `zip`
target field. You need to change the index to 5. 
This instructs the data mapper to map the index 5 source 
content to the `zip` target field. After you change the index, 
the data mapper adds a padding field with an index of 4. The 
result looks like this: 

image:images/integrating-applications/Example-Adding-Padding-Mapping-3.png[Example entries with padding]. 

This mapping is now complete. Although the source field has additional 
content at index 6, (zip+4), the target does not need the data and 
nothing needs to be done. 
