1. Problem
You would like to use
constant values within a BizTalk map. This might be because of preset
output map values within a destination schema (that do not exist in the
source schema) to assist in general programming concepts when using
functoids, or for other reasons.
2. Solution
To demonstrate how to add map
constants using the BizTalk Mapper, suppose that you want to use a
constant in conjunction with a String Extraction functoid. In this
example, you would like to extract a specified number of characters
(five) from the left of the source element value. In the source schema, Customer,
you have Zip elements like this:
<Zip>98103-00001</Zip>
In the destination schema, CustomerRecord,
you have Zip elements like this:
<Zip>98103</Zip>
To map constants, follow
these steps:
Set
up the BizTalk map with the appropriate source and destination schema,
as shown in Figure 1.
In the left pane, click the
Toolbox, and then click the String Functoids tab.
Click and drag a
String Left functoid onto the map surface.
Click the Zip element in the source schema and drag it
across to the left point of the String Left functoid.
Click
the String Left functoid on your map surface, and select Input
Parameters in the Properties window. The
Configure Functoid Inputs dialog box is now displayed, as shown in Figure 2. Notice the first input parameter is
the source schema's Zip element.
This is automatically configured as a result of dragging the source Zip element onto the map surface.
In the Configure Functoid
Inputs dialog box, click the Index row (BizTalk will automatically add
required input variables).
Type in the value 4. As noted, you are extracting five characters for the zip
code. Because the functoid is zero-based, the start position will be 0
and the end position will be 4, resulting in five characters.
Click OK to complete the functoid configuration.
Click
on the right side of the String Left functoid and drag it across to the
Zip element in the
destination schema.
Now, drag a String
Concatenate functoid onto the mapping surface. Double-click the
functoid. A default input will be available; ignore this, and click the
Plus button. Type the value USA. Delete the unused input (you may have to
reorder using the up/down arrows). The final values should look like
that shown in Figure 4. Click OK.
Drag the output of
this new String Concatenate functoid to the Country node in the map.
3. How It Works
You might use constant
mapping for the following:
To support functoid
configuration, as in the example in this recipe, which used the String
Left functoid.
For
values declared and assigned within a Scripting functoid. In essence,
these values can be mapped as output into destination values.
Furthermore, they can be declared once and accessed as global variables
within other Scripting functoids in the context of the working BizTalk
map.
With the String Concatenate functoid. Use the
input parameter of this functoid as the constant value required. This
functoid does not require any input values from the source schema. In
this usage, a String Concatenate functoid would simply be mapped through
to the desired destination value.
The best use of constant
mapping depends on the situation and requirements you are developing
against. Examine the likelihood of change within the scenario where you
are looking to apply the functoid constant. If there is a high
likelihood that values and their application will change, consistency
should be the major factor to facilitate maintenance.
If constants are set
via deterministic logic or complex or embedded business rules, it might
be worth thinking about whether the constant should be applied in the
map or applied within a scripting component or upstream/downstream
BizTalk artifacts. The key is understanding where rules and
deterministic values are set to support the specific situation. Apply
the appropriate design principles to ensure the correct constant
assignment technique is applied.
You might decide it would be
best to map values outside the mapping environment. This could be a
result of deterministic logic or business rules being the major
requirement in the constants implementation. Furthermore, rules that
derive constants may exist outside the BizTalk map. Constants may need
to change dynamically, and it may be too cumbersome to perform a
recompile/deployment for such changes within a BizTalk map.