Create a script in Jitterbit Integration Studio
Introduction
Scripts, written in either Jitterbit Script or JavaScript, provide the flexibility and power to transform data, perform calculations, or perform logic validation beyond simple field mapping.
Scripts can be used in multiple places, including within the design canvas as steps of an operation, as well as within transformations to apply specified logic or conditions to the data. The steps to create a script and perform further actions on a script are different depending on the type of script, as covered on this page.
Script types
There are three distinct types of scripts that differ in how they are created and used:
-
Script as a project component
This type of script can be used as a step in an operation and/or called using theRunScript
function. This type of script appears as a project component within the script component palette as well as within the project pane. The script language can be either Jitterbit Script or JavaScript. -
Script on a target field in a transformation
This type of script can be created on a field in a transformation to apply the specified logic to the transformation mapping. The last value returned in the script is used as the value for the target field. This type of script is available only on target fields in a transformation mapping. The script language must be Jitterbit Script. -
Condition script on a target node in a transformation
This type of script can be applied on a node in a transformation in order to determine if the source record being processed should be output to the target. If the script evaluates totrue
, then the record is output. If the script result evaluates tofalse
, then the record is skipped. This type of script is available only on target nodes in a transformation mapping. The script language must be Jitterbit Script.
Note
The script language used within transformations is limited to Jitterbit Script. Scripts used within operations can use either Jitterbit Script or JavaScript.
Script as a project component
This type of script is a project component that can be used as a step in an operation or called by another script using the RunScript
function. As an example, you could use a script as a step in an operation before or after an activity to retrieve data and then process script logic, or you could run a validation script before proceeding to a transformation.
Create a script
A new script as a project component can be created from these locations:
- The project pane's Components tab using the Create New option on the Scripts category (see Components tab actions menu in Project pane Components tab).
- The design canvas using a drop zone (see Drop zone actions menu in Design canvas).
New scripts are created with the default name New Script. Subsequent new transformations with default names are appended with an incremented number in parentheses.
On creating a new script, the script editor opens for you to configure the script (see Script editor).
Script actions menu
After a script as a project component is created, menu actions for that script are accessible from these locations:
- The project pane's Workflows tab (see Component actions menu in Project pane Workflows tab).
- The project pane's Components tab (see Component actions menu in Project pane Components tab).
- The design canvas (see Component actions menu in Design canvas).
Each of these menu actions is available:
Menu Item | Description |
---|---|
View/Edit opens the script editor for you to build the script (see Script editor). | |
Cut places a copy of the script on your clipboard and deletes the original script from the project (see Component reuse). | |
Copy places a copy of the script on your clipboard (see Component reuse). | |
Duplicate creates a new, unreferenced script using the same configuration as the original script (see Component reuse). | |
Rename positions the cursor on the script name for you to make any edits as necessary. | |
View Dependencies changes the view in the project pane to display any other parts of the project that the specific script is dependent on (see Component dependencies, deletion, and removal). | |
Add to Group opens a dialog to create a new custom group or to add the script to an existing group (see Component groups). | |
Delete permanently deletes the script (see Component dependencies, deletion, and removal). | |
Remove removes references to the script as an operation step on the design canvas (see Component dependencies, deletion, and removal). |
Script on a target field in a transformation
This type of script can be added on a field in a transformation in order to apply the specified logic to the transformation mapping. The last value returned in the script is used as the value for the target field. As an example, you could use scripting to change field data from a string
to an integer
, concatenate values, or use a database lookup for a field.
Creating a new script on a target field is done during transformation mapping in either mapping mode or script mode and is limited to Jitterbit Script language.
To add a new script on a target field, either double-click the field name, or hover over the target field and click the add icon in the top right of a target field to open a menu of actions. From the menu, select Add Script:
To edit a script on a target field that already has a mapping, either double-click the field name, or click the script icon in the top right of a target field.
These open the editable script area on the target field in script mode, where you can enter or edit the script logic for the mapping:
To view the full script editor with all available options for the script, click the popout icon in the upper right. For details, see Script editor. Close the full script editor to return to this screen.
To remove the script, simply delete the text of the script. For more information on this type of script, see Mapping with scripts.
Condition script on a target node in a transformation
A condition script is created on a target node in a transformation to determine if the 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 only be used if the size of a text field is less than a specified maximum.
Creating a new script on a target node is done during transformation mapping in either mapping mode or script mode and is limited to Jitterbit Script language. Conditions can be added as scripts on target nodes in any level of a data structure.
To add a new script on a target node, hover over the node name and click the actions menu icon to open the actions menu. From the menu, select Add condition to node:
This opens the editable script area on the target node in script mode, where you can enter or edit the condition script logic as appropriate. For example, the following condition script 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.
To view the full script editor with all available options for the condition script, click the popout icon in the upper right. For details, see Script editor. Close the full script editor to return to this screen.
To edit or remove the condition, hover over the node name and click the actions menu icon to open the actions menu. From the menu, select Edit condition or Remove condition:
For more information on this type of script, see Conditional mapping.