Coercions
In some situations, the datatype of a Scope Variables element may be undefined. In these situations, you may know the data type of the element, and you can coerce the element into a specific type. Using the Coercions button in the Input tab toolbar you can create and manage your coercions.
The following example illustrates a schema with an element defined as the "any element" data type. The schema is for a generic incoming message that can have any type of body. In the example, however, the any element is coerced into an Order type so that it can be mapped to a choice element.
The following procedure describes how to coerce the
Body
element of the incoming message into a specific datatype and map it to a choice element.
- Procedure
- Select the element of type any element in the Scope Variables schema. Click the
Coercions button in the
Input tab toolbar. In the Coercions dialog, click the
Insert button (+) to add a coercion for the currently selected element.
The Coercions dialog allows you to manage all of your coercions for a function in one dialog. You can create, modify, or delete coercions for any element in the Scope Variables schema using this dialog, not just the currently selected element. If you are creating a coercion for an element that is not currently selected, use the XPath field to specify the location of the element.
Click the Element radio button to specify that you are specifying a schema element.
- Click the Browse Resources button next to the Schema field to browse a list of schemas that can be used. In the Select a Resource... dialog, select the schema that you would like to specify
- Map the
Name
element to theName
element in the Function panel. Then, map the coercedOrder
element to the choice element in the Function panel.The Mapping Wizard dialog appears and asks if you wish to create an
Order
or aCreditLimitIncrease
element. SelectOrder
and click Next.The Mapping Wizard then asks you to create a For Each. Even though there is only one element in the Scope Variables schema (the
Message
element is not repeating), a For Each is used because this construct allows you to map the individual items of the Order element. Click Next to continue.The Mapping Wizard then asks if you wish to automatically map elements with the same name. Click Finish to accept the default mappings.
- The following is the completed mapping.