Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved


Appendix B Scripts : Managing Errors

Managing Errors
Retrying Document Posting
You can configure TIBCO BusinessConnect to retry posting of documents if it could not post them during the execution of the scripts. To do this, set the following in a script:
job.put("retryScripts", "true");
TIBCO BusinessConnect detects this value, and then does a retry. If you do not want retry to occur, you can set the value to be false:
job.put("retryScripts", "false");
For example, the sample scrip putediexample.txt has the retryScripts variable set if there are connection problems with the FTP server.
See TIBCO BusinessConnect Services Plug-in User’s Guide, First Tutorial Example for information on putediexample.txt.
For the error codes that TIBCO BusinessConnect might receive or might generate, see also com/tibco/ax/fw/runtime/transport/ftp/FTPReply and com/tibco/ax/fw/runtime/transport/sshftp/SSHFTPReply public interfaces in TIBCO BusinessConnect API Reference.
Returning Errors from Scripts
You can control the values returned in the statusCode and statusMsg fields following script execution. TIBCO BusinessConnect then uses these values for logging.
userStatusCode  Integer type
userStatusMsg   String message
By default, if job.get("userStatuscode") is not set in the script, it is assumed that the script was executed successfully. Hence, it is not necessary to specify status code 200 in the script for successful execution.
If you have to specify an error, you specify a statusCode other than 200, and an error will be logged and an advisory message on the Error subject will be sent. To do this, set the variable inside the scripts via the job slot variable.
Example:
job.put("userStatusCode", 553);
job.put("userStatusMsg", "Permission denied when storing the file on the FTP Server");
Audit Logging in Scripts
You can create an audit log within the context of a script. An audit log object is available as a job slot variable and this object can be used to log, for example, FTP login issues or in a case of inability to delete files due to inadequate file permissions.
The following line of code returns a UserLogAccess object:
var logClient = job.get("logObj");
You invoke this object using the log() method:
logClient.log(java.lang.String state,int status,java.lang.String desc)
This audit log object can be used to log the following status:
PENDING  Use if you want to do intermediate logging.
COMPLETED  Use if there are no errors are encountered and you want to end your audit trail for this execution of the script.
ERROR  Use if you encounter an error during the execution. Marking the status as ERROR would also internally trigger a TIBCO Rendezvous signal to be sent out in the following subject:
AX.BC.BC-INSTANCENAME.PROTOCOL.ERROR.TRANSPORT.SCRIPT
The status values are maintained in the Java interface UserLogAccess. The script examples discussed in TIBCO BusinessConnect Services Plug-in User’s Guide, FTP Script Examples include the UserLogAccess object which uses the constants to set the status of the audit log entry.
For every execution of the script, a new audit log summary row is created with the first call to the log() method triggering the creation of the row. This method allows the user to define the state, status, and description for the log entry. Please refer the JavaDoc API under UserLogAccess interface.
If logging is defined inside an FTP inbound script, the summary row would be logged with operation ID FTPGetScript and with a new document ID. Care should be taken when logging FTP inbound scripts.
The sample script mgetexample.txt (see TIBCO BusinessConnect Services Plug-in User’s Guide, First Tutorial Example) shows FTP Inbound scripts logging only if there is any error in the execution of the FTP scripts and thereby avoiding filling up the database with this audit trail.
If logging is defined inside an FTP outbound script, a summary row would be logged with operation ID FTPPutScript and a new document ID. If logging is defined inside a File script, whenever an outbound request is generated through scripts, a summary row would be logged with operation ID FILEScript and a new document ID.

Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved