Skip to end of metadata
Go to start of metadata

Introduction

Creating a condition on a target node, referred to as conditional mapping, lets you specify if a source record being processed should be output to the target based on a defined condition. The condition determines (yes or no) if the record is mapped. As part of that determination, you can include logic to set what values are used in the mapping. For example, a record might be used only if the size of a text field is less than a specified maximum.

Important Notes

When using a condition script on a target node, be aware of these notes:

  • Conditions can be added to target nodes on any level of the structure depending on the multiplicity as defined by the cardinality key.
  • Target nodes that can have a condition can have only one condition for each node. Thus, all logic for the condition must reside in that condition.
  • The condition script is always evaluated before any target fields are evaluated. This means that all logic for creating or determining the values for those target fields must be in the condition script if the condition script requires those values in order to complete its determination.
  • If multiple conditions are present, they are evaluated in the order from outer node to inner node; if they are on the same level, then they are evaluated in the order from top to bottom.

Adding a Condition

Conditions can be added as scripts on target nodes in any level of a data structure. From either mapping mode or script mode, hover over the node name and click the actions menu icon  to open the actions menu. From the menu, select Add condition to node:

Upon selecting this option, if you are not already in script mode, you will be brought into script mode to create a condition by entering a script on the selected node:

The contents of the script specifies the condition for generating the record. A condition must return a true (1) or false (0) value. It can contain other logic, and a side effect of that logic can be to set the value of other nodes in the transformation.

Example 1

The script below requires that the source object CleanStatus evaluates to true in order for the record to be processed. If CleanStatus evaluates to false, then the node is skipped and this particular record will not be processed:

Example 2

You can also use the == equals operator as shorthand to write condition scripts. For example, the same condition used in Example 1 could simply be written as this:

Example 3

To set a condition such that a record is used only if its flag to publish it was set, you could use a script such as this: 

bool(Publish_To_Community__c) == true

Example 4

To set a condition such that a record is used only if it is less than a maximum size, assuming that the article text is in the element json$results$item.body$view$value$, you could use a script such as this:

pass = true;

// Log article size
$articleDetailsSize = Length(json$results$item.body$view$value$);
WriteToOperationLog('Current article:' + 
    json$start$ + ' articleDetailsSize:' + $articleDetailsSize);

// Checks if the article size > $MaxArticleDetailSize;
// if so, the article is ignored
if($articleDetailsSize > $MaxArticleDetailSize, 
    WriteToOperationLog("Ignoring Id " + json$results$item.id$ + 
        " as too large (" + $articleDetailsSize + ")");
    pass = false;
);

pass;

Example 5

A condition script can also set values used in other nodes. Building off of Example 4, the condition node can, as part of its logic, set the intended contents of a field to a global variable:

...
$articleDetails = Replace(json$results$item.body$view$value$,
                          'href="/','href="https://example.com/');
...

The global variable is then used to set the value in the desired target field Article_Details__c:

$articleDetails;

Editing a Condition

To edit a condition, from either mapping mode or script mode, click the condition icon  that is displayed to the right of the target node:

Or, hover over the node name and click the actions menu icon  to open the actions menu. From the menu, select Edit condition:

If you are not already in script mode, you will be brought into script mode to edit the condition by editing the script on the selected node.

Removing a Condition

To remove a condition, from either mapping mode or script mode, hover hover over the node name and click the actions menu icon  to open the actions menu. From the menu, select Remove condition:

The contents of the script will be cleared, removing the condition.

You can also remove a condition by manually editing the condition script to clear the script of its contents.

On This Page

Last updated:  Jul 15, 2019

  • No labels