Conditional Mappings

Conditional Mappings

Overview

The DataMapper supports three types of conditional mappings to handle complex transformation logic:

  • if - Execute mapping only when a condition is met
  • choose-when-otherwise - Branch based on multiple conditions
  • for-each - Iterate over collection fields (arrays)

If Mapping

Create a mapping that only executes when a specific condition is true.

Steps

  1. Click the 3-dot menu on the target field and select “wrap with if”

    Select wrap with if
    Select wrap with if
    Select wrap with if

  2. Configure the condition - Drag source fields or type manually

    Define the if condition
    Define the if condition
    Define the if condition

  3. Create the mapping for when the condition is true

    Configure the conditional mapping
    Configure the conditional mapping
    Configure the conditional mapping

Tip

You can drag source fields into the condition input to quickly build expressions like $sourceField > 100 or $status = 'active'.


Choose-When-Otherwise Mapping

Create branching logic with multiple conditions, similar to switch-case statements.

Steps

  1. Click the 3-dot menu and select “wrap with choose-when-otherwise”

    Select choose-when-otherwise
    Select choose-when-otherwise
    Select choose-when-otherwise

  2. Configure when and otherwise conditions - Similar to if mapping, configure the condition and create mappings for both when and otherwise branches

    Configure when and otherwise mappings
    Configure when and otherwise mappings
    Configure when and otherwise mappings

  3. Add more when branches (optional) - If you need multiple conditions, click the 3-dot menu on the choose field and select “Add when” to create additional when branches. Each branch can have its own condition and mappings.

    Add another when branch
    Add another when branch
    Add another when branch

Note

The otherwise branch executes when none of the when conditions are satisfied, providing a default fallback.


For-Each Mapping

When working with arrays or repeating elements, use for-each mappings to transform each item in the collection. Collection fields are identified by a layer icon Layer icon in the document tree.

Steps

  1. Identify the target collection field - Look for fields marked with the layer icon Layer icon, indicating they contain multiple items

  2. Create the for-each mapping - Click the 3-dot menu on the target collection field and select “wrap with for-each”

    Select wrap with for-each
    Select wrap with for-each
    Select wrap with for-each

  3. Specify the source collection - Choose which source collection to iterate over. This determines what data will be processed for each target item.

    Select source collection to iterate
    Select source collection to iterate
    Select source collection to iterate

  4. Map the collection item fields - Create mappings for individual fields within each collection item. These mappings will be applied to every item in the collection.

    Map fields for each collection item
    Map fields for each collection item
    Map fields for each collection item

Important

Inside a for-each mapping, field paths are relative to the collection item. For example, if iterating over Items, you reference Name instead of Items/Name.


Sorting For-Each Results

When iterating over a collection with for-each, you can configure sorting to control the order of the output elements. This adds xsl:sort to the generated xsl:for-each.

Steps

  1. Create a for-each mapping as described above

  2. Click the 3-dot menu on the for-each node and select “Configure Sort”

    Select Configure Sort from the for-each context menu
    Select Configure Sort from the for-each context menu
    Select Configure Sort from the for-each context menu

  3. Configure sort keys in the modal dialog — enter the XPath expression for the field to sort by, or use the dropdown to select a field

    Configure Sort modal with sort key and options
    Configure Sort modal with sort key and options
    Configure Sort modal with sort key and options

  4. Add additional sort keys (optional) — click “Add sort key” to add secondary sort criteria. Items are sorted by the first key, then by the second key for ties, and so on. Drag the handle on the left to reorder sort keys.

    Add sort key
    Add sort key
    Add sort key

  5. Configure Ascending/Descending (optional) - click Ascending/Descending button to toggle the direction

    Ascending/Descending
    Ascending/Descending
    Ascending/Descending

  6. Re-order sort keys by drag-and-drop (optional)

    Re-order sort keys
    Re-order sort keys
    Re-order sort keys

  7. Configure sort key advanced properties (optional) - click slider button on the sort key to expand advanced properties

    Configure Sort key advanced properties
    Configure Sort key advanced properties
    Configure Sort key advanced properties
    Advanced properties expanded
    Advanced properties expanded
    Advanced properties expanded

  8. Click Save to apply the sort configuration

    Save sort configuration
    Save sort configuration
    Save sort configuration


Multiple For-Each Mappings

Merge multiple source collections into a single target collection by adding multiple for-each mappings.

Steps

  1. Create the first for-each mapping as described above

  2. Add another for-each mapping - Click “Add Conditional Mapping” in the placeholder below the first mapping, then select “Wrap with for-each”

    Add second for-each mapping
    Add second for-each mapping
    Add second for-each mapping

  3. Configure the second collection mappings - Select the second source collection to iterate over, then create field mappings for each item. This allows you to merge data from multiple collections into a single target array, combining items from different sources.

    Configure second collection and map its fields
    Configure second collection and map its fields
    Configure second collection and map its fields

Tip

This technique is useful for merging data from multiple sources, such as combining orders from different systems into a single output array.


Next Steps

Now that you understand conditional mappings:

  1. Use the XPath editor for complex expressions with functions
  2. Return to the DataMapper overview to explore other features
docs