Using Layers
You can separate complex mappings into multiple layers. But, you can also create conditional layers that execute if a conditional expression evaluates to true.
You can use the layer toolbar, at the bottom of the function window, to create, edit, list, and simulate and layers. Right-click in the mapping area to execute other commands, like sending a selection to a layer or showing all layers.
- See Also
- See Simulating Mappings for guides to troubleshoot a mapping in the mapping simulator.
Adding a Layer
Open the SubFunction in a function window and do one of the following:
- Click the add button
in the mapping area's toolbar. - Right-click in the mapping area, then click Add New Layer.
In the dialog box that's displayed, specify the layer's settings.
Configuring Layer Settings
Specify the following settings to create a layer. To edit a layer's settings, do one of the following:
- Click the
button in the toolbar at the bottom of the mapping area. - Right-click the mapping area and then click Change Layer Definition.
You can specify the following settings:
| Layer Name | The layer's name. |
|---|---|
| Condition | The Mapper component maps the layer if the conditional expression you specify here evaluates to true. If you don't specify a conditional expression, the Mapper always maps the layer. |
| For each row | Select this option to evaluate the condition for each row. Otherwise, the Mapper only evaluates the condition when it processes the first row. |
| Description | Enter the text of the tooltip when you hover over the layer's tab. |
Designing Layers
See below for graphical workflows to design a mapping that executes multiple layers.
- Changing the Execution Order
- Overwriting Values
- Showing All Layers
- Moving Output Mappings
- Listing Layers
- Deleting a Layer
- Cloning a Layer
Changing the Execution Order
The Mapper executes conditional layers after normal layers, from the leftmost tab to the rightmost. You can rearrange the layers' tabs to change the order that layers execute in. But, you can't move a conditional layer before a normal layer. The tabs for conditional layers are highlighted in light blue.
Changing the order of normal layers doesn't impact the results of the mapping, since normal layers are merged into a single layer. But, the order of the conditional layers does impact the results, as conditional layers can overwrite output values.
Overwriting Values
Conditional layers can overwrite values. Unlike in a normal layer, you can map the same output in multiple conditional layers. If multiple conditional layers execute that map the same output, the conditional layers overwrite the value.
Conditional layers can also overwrite values if you use the logical and/or operators and select the For Each Row option. If the condition's true for multiple rows, the conditional layer executes multiple times and overwrites the values it mapped previously.
Showing All Layers
Right-click in the mapping area then click Show All Layers.
Moving Output Mappings
You can move the chain of links and mapper functions that define the mapping of an output. You don't need to select all the links in the chain: You can click to select one item, right-click, and click Send to Layer. The Flow Designer moves the chain of mapper functions that make up the mapping.
You can also drag to select the mappings to multiple outputs, along with descriptions.
Listing Layers
You can do the following to display a dialog box that lists the layers you've defined and their descriptions:
- In the function window's toolbar, click
. - Right-click the mapping area then click List Layers.
Deleting a Layer
Do one of the following:
- Click the layer's tab to open the layer you want to delete.
- Click the
button. Or, right-click in the mapping area then click Remove Layer.
Cloning a Layer
You can right-click in the mapping area and click Clone Layer. In the dialog box that's displayed, configure the layer's settings.
Note
Normal layers are merged into a single layer. You can't map one field in multiple layers. So, when you clone a normal layer, the fields you mapped in the original layer are disconnected in the cloned layer. You can see the fields you already mapped in another layer highlighted in light blue.
Building Conditional Expressions
You build conditional expressions using literal values, comparison operators, and objects. Query the available objects to get linked inputs, parameters, and other input information.
Syntax Examples
The examples below introduce the expression syntax.
Literal true and false
You could specify the boolean literal values true or false as a way to branch execution.
Get a linked input
Select linked inputs by the order of the inputs.
$input.1 < 3
Note
Get a function parameter
Select the parameter name from the $param object:
$param.filename = "aaa.txt"
Get the link count
Select the $function object's LinkCount attribute to return the number of inputs linked to the function:
$function.LinkCount < 2
Getting Inputs
You can use the following objects to get linked inputs and function parameters.
| Description | Syntax |
|---|---|
| Linked inputs | $input.<input number> $function.LinkCount |
| Function parameters | $param.<function parameter name> |
Using Comparison Operators
You can use the following comparison operators:
| = | Equal |
| != | Not equal |
| > | Greater than |
| < | Less than |
| >= | Greater than or equal to |
| <= | Less than or equal to |
| ~= | Contains (the right side must be a string) |
| !~ | Doesn't contain (the right side must be a string) |
Note
- Strings are compared alphabetically, as in the dictionary. (Java string comparison is used internally.)
- If the right side of "~=" and "!~" is not a string, the result is false.
Using "and" and "or" Operators
You can use "&&" and "||" to connect conditional expressions using the boolean logical "and" and "or" operators.
Converting Data Types
The data type of the field on the left side is automatically converted to the data type on the right side. For example, consider the following expression:
$param.FilePath = "aaa.txt"
The value on the right side is a string, since it's enclosed in double quotes, so the FilePath field specified on the left is automatically converted to a string.
If the type conversion fails with an error, the result of the conditional expression is regarded as "false" and the mapping of that layer is not performed.
Error Cases
See below to follow the mapping when an error occurs:
- If an error occurs while evaluating the conditional expression, like a type conversion error, the conditional expression evaluates to false and the layer isn't mapped.
- If an error occurs while the SubFunction maps a conditional layer, the SubFunction throws an exception.
Note that in both cases, the data still reflects the changes from the layers before.