Conditional mapping in transformations in Jitterbit Integration Studio
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 with a cardinality of
[0+]
,[0, 1]
, or[1+]
on any structure level. If a node is required ([1+]
) and the condition evaluates tofalse
, the operation may fail at runtime. - 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.
Add a condition
You can add conditions as scripts on target nodes with a cardinality of [0+]
, [0, 1]
, or [1+]
. 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:
On selecting this option, if you are not already in script mode, you are brought into script mode to create a condition by entering a script on the selected node:
The contents of the script specify 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.
Note
If the node is required ([1+]
) and the condition evaluates to false
, the operation may fail at runtime.
Example 1
The script below requires that the source object code
evaluates to true
in order for the record to be processed. If code
evaluates to false
, then the node is skipped and this particular record is not 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 be written like this:
Example 3
To set a condition such that a record is used only if a 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;
Edit a condition
From either mapping mode or script mode, click the orange condition icon 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 are brought into script mode to edit the condition by editing the script on the selected node.
Remove a condition
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 Remove condition:
The contents of the script are cleared, removing the condition.
You can also remove a condition by manually editing the condition script to clear the script of its contents.