Skip to end of metadata
Go to start of metadata

The Jitterbit scripting language can be used in all types of scripts within Jitterbit, including scripts created as project items within operations as well as scripts within transformation mappings. See Creating a Script for instructions on creating a script and using the script builder in Jitterbit.

Syntax

Each Jitterbit script is always surrounded by a set of <trans>...</trans> tags. This applies to scripts created as project items, as well as to "Formula Builder" scripts created within transformation mappings.

NOTE: The result that is returned in a Jitterbit script or formula will be the returned value of the last statement of the script before the closing </trans> tag.

Within the <trans>...</trans> tags, "//" marks the start of a comment, and affects the text to the end of that line. Comments will not be part of the script that is run or the transformed result.

For example, a comment on a single line might look like this:

Single-Line Comment in Jitterbit Script
<trans>
// This is a comment
DbLookup(...)
</trans>

You can also use a block-style comment:

Multi-Line Comment in Jitterbit Script
<trans>
/* This is a multi-line comment
This line is also a comment
This is the final line of the comment */
DbLookup(...)
</trans>

In addition, Jitterbit supports regular expressions as means of specifying and recognizing strings of text, including particular characters, words, or character patterns. Jitterbit supports the regular expression syntax from the Perl 5 programming language.

<trans>
RegExMatch(<input>,<expression>,...)
</trans>

For more information, see  http://www.boost.org/doc/libs/1_49_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html.

Functions and Data Elements

A Jitterbit script consists of built-in functions, data elements, or logic to execute, separated by a semi-colon (;). The Jitterbit script language has few control structures, but has many functions specifically designed for data manipulation.

Functions

All of the built-in Jitterbit functions that are available under the Functions tab when creating a script are available for reference under Formula Builder.

Global Data Elements

In addition, you can access all global data elements under the Data Elements tab when creating a script. These include global variables, project variables, and Jitterbit variables. See Using Project Variables and Using Global Variables for more information. Jitterbit variables are documented individually under the Reference section.

Global data elements are accessed either by typing a $ sign before the element name or by using the Set and Get functions.

Variable names can be composed from these characters: letters (a-z, A-Z), numbers (0-9), period, and underscore. Other characters are not permitted. (Note that in the case of local variables, the period character is not allowed.)

This example references a global data element using $ to create a global dictionary:

<trans>
$org.lookup.currency=Dict();
$org.lookup.currency[1]="USD";
$org.lookup.currency[2]="EUR";
</trans>

This example assigns a global data element to another global data element using the Set and Get functions:

<trans>
Set("op2", Get("op"));
</trans>

Note that for certain Jitterbit variables, because they describe data elements that do include a hyphen, you must reference them by using either the Set or Get functions:

<trans>
Get("jitterbit.networking.http.request.header.content-type");
</trans>

Source Data Elements

If you are using a script created within the transformation, you also have access to source data elements. Source data elements are used to reference source data and are referred to by their paths in the source tree. More information is provided under Creating a Script

This example assigns a source data element to a global data element:

<trans>
$org.calculate.operand1=root$transaction.request$body$Calculate$input.Operand1$;
</trans>

Local Data Elements

You can also use local data elements, also known as local variables, that you create and use within the same script. See Using Local Variables for more information. Characteristics of local data elements are as follows:

  • A local data element is defined and used only within the expression; once its value is assigned in the expression, the local data element is deleted. Therefore, conflict between a local data element's value in the present expression and those from other expressions is not a concern.
  • The local data element cannot be defined or retrieved by the set()/get() functions.
  • RunScript() can pass arguments to the script, e.g. RunScript(SCRIPT_ID, 5, "abc",...). Values in the script can be assigned to predefined local variables _1, _2... In this example _1 represents the integer value of 5, while _2 represents the string value "abc". The local variable must be defined before it can be referenced, except in the case of the input arguments _1, _2,... described above.
  • The ArgumentList() function is available for redefinition of a list of local data elements as input arguments.

Data Types

All source data elements and global data elements that are not null have a type associated with them. Jitterbit supports the following data types: Integer, Long, Float, Double, Date, String, Boolean, Timespan, Bit, Binary, and Array. Data element types can be changed using the functions in the Conversion category.

Arrays

An array is a collection of data elements. Each member in the collection can be of any supported type, including arrays. The members of an array can be accessed using the Get() and Set()methods or using the [] array syntax. Arrays are zero-indexed, and indices are numeric, sequential, and cannot be skipped. 

You can also create arrays of global variables. An array global variable is an array of other global variables that in turn can be arrays. 

Setting an Array

You can set values in an array using the Set() method with this syntax:

type Set(string name, type value [, int index1, int index2, ...])

This sets the value of the global variable with the given name to value, and returns the value. If the first argument is an array or the name of an array data element, you can set the value of an array element by specifying its index (or indices for multi-dimensional arrays) as the third argument.

Not all the items in an array have to be of the same type. For example, you can create an array that holds a date, an integer, and a string. You can even create arrays inside other arrays.

This example creates an array with three elements of different types where each entry represents the current date and time:

<trans>
$right_now = Now();
Set($now, $right_now, 0);
Set($now, Long($right_now), 1);
Set($now, String($right_now), 2);
</trans>

Arrays are zero-indexed, i.e. the first element is at index 0 and the last element is at index size-1. To append data to an array, pass a negative index value or the size of the array. Setting an element with index larger than the size of the array results in an index out of range error. Setting non-array data elements can also be done using the $de_name syntax.

These are examples of setting values in an array:

// Set the n:th entry in an array to the string "value"
Set($arr, "value", n-1);

// Set the n:th entry of the m:th array
Set($record_set, "value", m-1, n-1);

// This is another way to set the n:th entry of the m:th array
Set($arr, "value", Length($arr));

// Sets the value to a new element at the end of the array
Set($arr, "value", -1);
NOTE: For additional syntax that can be used to define values in an array, see the Dictionary and Array Functions.

Accessing an Array

You can access the items of an array using the Get() method with this syntax:

type Get(string name[, int index1, int index2, ...])

This returns the value of the global variable with the given name. If the first argument is an array or the name of an array data element, you can get a specific element by specifying its index (or indices for a multi-dimensional array such as a record-set) as the second argument.

Some Formula Builder functions have array return values. For example, SelectNodesFromXMLAny()returns the results of an XPath query as an array. As another example, DbExecute() returns a record set as a two-dimensional array: rows first, then columns. This returns the selected data as an array of arrays (representing the selected rows and columns):

<trans>
$resultSet = DbExecute("Project Name/Sources/Database Name", "select Result from SimpleCalculatorResults");
$firstRow = Get($resultSet, 0);
$thirdColumnOfSecondRow = $resultSet[2][3];
$secondColumnOfThirdRow = Get($resultSet, 3, 2);
</trans>

Arrays are zero-indexed. To access the n:th element of an array called "arr", use Get("arr", n-1). For multi-dimensional arrays you need to specify all the indices. To access the n:th column of the m:th row in an array called ResultSet you would use Get("ResultSet", m-1, n-1). Attempting to get an element beyond the end of the array will result in an array out-of-range error.

These are examples of retrieving values from an array:

// Return the third array element
Get($arr, 2);

// Another way to return the third array element
Get("arr", 2);

// Get the n:th element of the m:th array in arr
Get($arr, m-1, n-1);

This example shows how you can first create a script that builds and returns an array. The second block shows running that script and assigning its returned value to a variable.

Build Array
<trans>
// Script to build and return an array
a = Array();
a[Length(a)] = "A";
a[Length(a)] = "B";
a[Length(a)] = "C";
a;
</trans>
Call Script to Get Array
<trans>
// Call the script to retrieve the array
$Arr = RunScript("<TAG>Scripts/Build Array</TAG>";
</trans>
NOTE: For additional syntax that can be used to access values in an array, see the Dictionary and Array Functions.

Dictionaries

In Jitterbit, a dictionary is a special type of global variable array that holds key-value pairs. The steps and functions are:

  1. Initialize the dictionary using the Dict function:

    $d = Dict();
  2. Load data with a key and a value:

    $d['4011'] = 'Banana';
    $d['4063'] = 'Tomato';
  3. Check if the key already exists in the dictionary using the HasKey function:

    HasKey($d,'4011'); // Returns true

    In the example, we have already loaded the key '4011' so HasKey would return true.

    HasKey($d,'4089'); // Returns false

    If the key were not already loaded, for example '4089' the HasKey would return false.

  4. Look up the value in the dictionary by passing the key and getting back the value:

    $d['4011']; // Returns 'Banana'

    In this example, the value returned would be Banana.

With dictionaries, keep these characteristics in mind:

  • The scope of dictionaries is limited to the workflow. For example, if an operation loads $MyDict with 10,000 records, only those operations that are linked using On Success or On Failure paths, or with RunOperation() will have access to that dictionary. But, if an operation uses chunking and threading, and has a transformation that populates a dictionary, the dictionary will be inconsistent. This is because Jitterbit does not take the values assigned to variables by multiple operation threads and concatenate into a single value set. This is true for all global variables or arrays. Use the default chunking/threading values when building an operation that populates dictionaries. 
  • Dictionaries, because they use a binary search, are very fast at finding keys and returning values. A key can usually be found within five to six tries. In contrast, compare this type of search to looping through a 10,000 record array to find a key.  
  • Dictionaries are not written to memory, so they will not materially impact available server memory for processing.

Operators

This is a summary of the operators supported by Jitterbit script. Jitterbit script will attempt to convert the arguments to enable the operation. If this is not possible, an error will be reported.

OperatorDefinition
=For assignment of a variable. The right-hand argument will be assigned to the left-hand argument.
+Add two numbers or concatenate strings. If a string is added to anything else, both arguments are converted to strings. If both arguments are numbers, the result will be of type double.
++Increments the value by 1. Example: $count++;
+=Concatenates the string or adds numbers to the target variable. Example: $count+=2; is the same as $count=$count+2;
-Subtract two numbers. The result will be of type double.
/Divide two numbers. The result will be of type double.
*Multiply two numbers. The result will be of type double.
&Logical AND operator. The result will be of type boolean. && can also be used. This is always a short-circuit operator, meaning that if the left-hand argument evaluates to false, the right-hand argument will not be evaluated.
|Logical OR operator. The result will be of type boolean. || can also be used. This is always a short-circuit operator, meaning that if the left-hand argument evaluates to true, the right-hand argument will not be evaluated.
==Equals operator. Returns true if the arguments are equal. Returns false is they are not equal.
!=Not equals operator. Returns true if the arguments are not equal. Returns false if they are equal.
<
>
<=
>=
Comparison operators.
!Negation operator. Converts a true value to false, and vice versa. Example: !IsNull($org.workorder.id)
{ }

Used to build an array. Example:

$a = {"London", "Paris", "New York"};
$b = {{"John",25},
      {"Steve",32},
      {"Daniel",26}
     };
$c = {"\"quoted\"", '"quoted"'};

Escape Sequences

Jitterbit recognizes these escape sequences when used in literal strings:

SequenceDefinition
\tTab
\rCarriage return

\n

New line

Literal strings have to be surrounded by double quotes (") or single quotes (').

The "other" quote has to be escaped if used in the string. For example:

$str = "String with line break.\nThat's the last line.";

$str = 'Tony "The Gun" Marcello';

$str = "Tony \"The Gun\" Marcello";

Control Structures

The Jitterbit Script language does not include control statements such as if or while loops. Instead, you can use Jitterbit functions to achieve the same functionality. See the Case, If, and While functions under Logical Functions. The Eval function under General Functions can be used as a "try-catch" statement.

NOTE:

  • The maximum number of loop iterations allowed in Jitterbit Harmony is 50,000.
  • The maximum number of loop iterations in Jitterbit Script Language is per each individual loop. To increase the allowed number of iterations per loop in a Jitterbit Script Language script, see jitterbit.scripting.while.max_iterations in Scripting Jitterbit Variables.
  • The maximum number of loop iterations in JavaScript is per script (aggregate of all loops within one script). To increase the maximum number of loop iterations in JavaScript, see Java Script Loop in JavaScript.

On This Page

Last updated:  Mar 27, 2019