Skip to Content

Script Types and Creation

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 the RunScript 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 to true, then the record is output. If the script result evaluates to false, 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:

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:

Each of these menu actions is available:

Menu Item
Description
view edit View/Edit opens the script editor for you to build the script (see Script Editor).
cut Cut places a copy of the script on your clipboard and deletes the original script from the project (see Component Reuse).
copy Copy places a copy of the script on your clipboard (see Component Reuse).
duplicate Duplicate creates a new, unreferenced script using the same configuration as the original script (see Component Reuse).
rename Rename positions the cursor on the script name for you to make any edits as necessary.
view dependencies 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 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 Delete permanently deletes the script (see Component Dependencies, Deletion, and Removal).
remove 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 add 2 in the top right of a target field to open a menu of actions. From the menu, select Add Script:

target field 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 script 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:

source objects cropped

To view the full script editor with all available options for the script, click the popout icon popout 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 actions menu 22 to open the actions menu. From the menu, select Add condition to node:

target node add condition

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.

condition if

To view the full script editor with all available options for the condition script, click the popout icon popout 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 actions menu 22 to open the actions menu. From the menu, select Edit condition or Remove condition:

target node remove condition

For more information on this type of script, see Conditional Mapping.