Jitterbit JavaScripts can access—in addition to the standard JavaScript functions that are part of ECMA-262 v5.1—these Jitterbit-specific functions. As ECMA-262 v5.1 is an older version of JavaScript than what is commonly available in browsers and other JavaScript engines, we've included tables of the common and standard JavaScript functions that are available in Jitterbit JavaScripts.
array Jitterbit.DbExecute(string databaseId, string sql) int Jitterbit.DbExecute(string databaseId, string sql, string outputVariable,...) |
Jitterbit.DbExecute(<databaseId>, <sql>) Jitterbit.DbExecute(<databaseId>, <sql>, <outputVariable>,...]) |
databaseId
: A string Database source in the current projectsql
: The SQL command to be executed against the databaseoutputVariable
: (Second form) An output parameter that is matched to fields returned in the SQL command. Additional arguments can be specified as required.Executes a SQL statement on a database and returns the results. See the Jitterbit Script DBExecute
function for details.
string Jitterbit.DbLookup(string databaseId, string sql) |
Jitterbit.DbLookup(<databaseId>, <sql>) |
databaseId
: A string Database source in the current projectsql
: The SQL command to be executed against the databaseExecutes a SQL statement on a database and returns the first field of the first result matching the specified criteria. See the Jitterbit Script DBLookup
function for details.
string Jitterbit.GetVar(string jitterbitVariableName) |
Jitterbit.GetVar(<jitterbitVariableName>) |
jitterbitVariableName:
The name of a Jitterbit VariableReturns the value of either a Jitterbit variable (the predefined global variables that are built into Jitterbit and begin with "$jitterbit.
"). The dollar symbol is optional and can be omitted.
The available variables can be seen in the Jitterbit Studio and are documented under Jitterbit Variables.
// Retrieves the value of the Jitterbit variable "jitterbit.api.request" var request = Jitterbit.GetVar("$jitterbit.api.request"); |
string Jitterbit.ReadFile(string sourceId[, string fileFilter]) |
Jitterbit.ReadFile(<sourceId>[, <fileFilter>]) |
sourceId:
File-type source in the current projectfileFilter:
File filter or filename to override the source definitionReads the contents of a file from a source.
The file-type source used in this function call must be defined as a source in the current project.
See the instructions on inserting project items.
The method returns the contents of the file pointed to by the source. If the source filter selects more than one file, the first one will be used. It is recommended to specify a source that uniquely identifies a single file.
The parameter fileFilter
is optional and can be used to override the file filter used in the source definition. A filename can be used. Alternatively, a global variable can be used to override the file filter in the source definition. Global variables are referenced as [de_name]
in the source definition.
As of Harmony version 8.20, if the ReadFile
function fails, the operation does not fail. A script will abort, a warning added to the operation log, and the operation will continue.
This method can be used to read data from an HTTP source. In that case, all Jitterbit $jitterbit.source.http.*
variables will be populated.
// Reads the first file retrieved from a source var fileContents = Jitterbit.ReadFile("<TAG>Sources/Customer CSV FTP</TAG>"); // Use the filename "test.txt" instead of what is defined in the source var fileContents = Jitterbit.ReadFile("<TAG>Sources/Customer CSV FTP</TAG>", "test.txt"); |
Jitterbit.SetVar(string jitterbitVariableName, string value) |
Jitterbit.SetVar(<jitterbitVariableName>, <value>) |
jitterbitVariableName:
The name of a Jitterbit Variablevalue:
A value to be assigned to the variableSets the value of a Jitterbit variable (the predefined global variables that are built into Jitterbit and begin with "$jitterbit.
"). The dollar symbol is optional and can be omitted.
The available variables can be seen in the Jitterbit Studio and are documented under Jitterbit Variables.
// Sets a Jitterbit variable Jitterbit.SetVar("$jitterbit.scripting.db.max_rows", 1000); |
void Jitterbit.WriteFile(string targetId, type fileContents[, string filename]) |
Jitterbit.WriteFile(<targetId>, <fileContents>[, <filename>]) |
targetId:
File-type target in the current projectfileContents:
Data to be written to the filefilename:
Filename to override the target definitionWrites the fileContents
to the file-type target specified by targetId
. If fileContents
is of type binary, the binary data is written to the file. In all other cases, a string representation of the data is written. The file is automatically flushed and closed by the function.
The file-type target used in this function call must be defined as a target in the current project.
The available variables can be seen in the Jitterbit Studio and are documented under Jitterbit Variables.
The third parameter, filename
, is optional and can be used to override the filename used in the target. Alternatively, a global variable can be used to override the filename in the target definition. Global variables are referenced as [de_name]
in the target definition.
This method can also be used to write/post data to an HTTP target. In that case, $jitterbit.target.http.*
variables will be populated.
As of Harmony version 8.20, if the WriteFile
function fails, the operation does not fail. A script will abort, a warning added to the operation log, and the operation will continue.
// Writes the value of $contents to the file defined by a target Jitterbit.WriteFile("<TAG>Targets/FTP Target</TAG>", $contents); // Use the filename "test.txt" instead of what is defined in the target Jitterbit.WriteFile("<TAG>Targets/FTP Target</TAG>", $contents, "test.txt"); |
void SetScriptOutput(string data) |
SetScriptOutput(<data>) |
data:
Data to be returned by the scriptSets the value returned by a script.
The return value of a script can be accessed as the return value of the RunScript
function.
// In the calling Jitterbit Script script: $result = RunScript("<TAG>Scripts/CalculateSomething</TAG>", value_to_be_calculated); // In the Jitterbit JavaScript script "CalculateSomething": var calculated_value = ...; ... SetScriptOutput(calculated_value); |
void SetScriptResult(string data) |
SetScriptResult(<data>) |
data:
Data to be returned by the scriptAn alias for the SetScriptOutput
function. See SetScriptOutput
for details.
string WriteToOperationLog(string message) |
WriteToOperationLog(<message>) |
message:
A string messageWrites a message to the Operation Log.
// Writes a message to the Operation Log WriteToOperationLog("The source field 'Price' has an invalid value."); |
These common JavaScript functions—part of ECMA-262 v5.1—are supported in Jitterbit JavaScripts.
Common Property | Description |
---|---|
Array | See the JavaScript Array properties and functions |
Date | See the JavaScript Date properties and functions |
| Decodes a URI |
| Decodes a URI component |
| Encodes a URI |
| Encodes a URI component |
| Evaluates a string and executes it as if it were JavaScript code |
| Tests if a value is a finite and legal number |
| Tests if a value is an illegal number |
| Parses a JSON string and returns a JavaScript object |
| Converts a JavaScript object into a JSON string |
Math | See the JavaScript Math properties and functions |
| Converts an object's value into a number |
| Parses a string and returns a floating point number |
| Parses a string and returns an integer |
| See the JavaScript String properties and functions |