Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Logging and error functions can and should be used to provide appropriate reactions to script actions.

Excerpt

GetLastError

Declaration

Code Block
string GetLastError()

Syntax

Code Block
GetLastError()

Description

Returns the last error reported in a script or transformation. It can be used with the ResetError() and Eval() functions for error handling.

Note that the GetLastError() function does not carry the error message over into another operation. To do that, Jitterbit variables are available that contain that information for use between operations:

  • $jitterbit.operation.error
  • $jitterbit.operation.previous.error
  • $jitterbit.operation.last_error

See also the RaiseError() function.

Examples

Code Block
// Discard previous errors
ResetLastError();
error = "";

// On failure, put the last error into a variable
Eval(orderType = DBLookup("<TAG>endpoint:database/My Database</TAG>",
  "SELECT ORDER_TYPE FROM PO_HEADER WHERE PO_NUMBER = " + PO_NUM),
  error = GetLastError());

// If an error, raise it with the error in the message
If(Length(error) > 0,
  RaiseError("Failed to lookup Order Type: "
    + error), orderType);

Backtotop

RaiseError

Declaration

Code Block
void RaiseError(string message)

Syntax

Code Block
RaiseError(<message>)

Required Parameters

  • message: A string message

Description

Causes a script or transformation to fail, and the contents of the parameter message to be displayed in the error log. 

The entire text written to the error log will be:

Fatal Error
<message>
This error was raised by a call to the RaiseError function.

Warning

WARNING: The RaiseError() function should be used as a last-resort, as it raises a fatal error. If a script raises it, there is no control by the calling program on what is produced to the client. Jitterbit does not have a "raise-and-capture" exception mechanism, and raising this error will result in a Server Error with a Status of 500. Instead, programs should test for inputs and outputs and handle conditions defensively.

Examples

Code Block
message = "The source field "
  + "'Price' has an invalid value. Exiting.";
RaiseError(message);

Backtotop

ResetLastError

Declaration

Code Block
void ResetLastError()

Syntax

Code Block
ResetLastError()

Description

Sets the last error to an empty string. This is identical to calling SetLastError(""). See also the function SetLastError().

Examples

Code Block
// Reset the last error
ResetLastError();

Backtotop

SetLastError

Declaration

Code Block
void SetLastError(string message)

Syntax

Code Block
SetLastError(<message>)

Required Parameters

  • errorMessage: A string message

Description

Sets a user-defined last error. The message will be logged as a warning and the GetLastError() function will return the message unless another error occurs. See also the function ResetLastError(), which performs the same action of setting the last error but without logging a message.

Examples

Code Block
// Sets the last error to a message
message = "Invalid value: source field 'Price'";
SetLastError(message);

Backtotop

WriteToOperationLog

Declaration

Code Block
string WriteToOperationLog(string message)

Syntax

Code Block
WriteToOperationLog(<message>)

Required Parameters

  • message: A string message

Description

Writes a message to the operation log.

Examples

Code Block
// Write a message to the Operation Log
WriteToOperationLog("The source field 'Price' has an invalid value.");

Backtotop

Panel
borderColor#65379B
titleColor#FFFFFF
titleBGColor#65379B
titleOn This Page
Table of Content Zone

Table of Contents
maxLevel2
minLevel2
excludeSyntax|Declaration|Description|Example.*|Required Parameters|Optional Parameters

Panel
borderColor#8C9CB4
titleColor#FFFFFF
titleBGColor#8C9CB4
titleSearch in This Topic
Page Tree Search
rootPageFunctions
Panel
borderColor#FF7C4C
titleColor#FFFFFF
titleBGColor#FF7C4C
titleRelated Articles
Panel
borderColor#00B886
titleColor#FFFFFF
titleBGColor#00B886
titleRelated Topics

HideElements
metastrue

Last updated: 

Lastmodifieddate