About the DebugReport Subroutine

Each scripting agent can be assigned an execution log, and you can have your script write messages to this log by assigning string values to the Script.Response intrinsic object. The Event Service allows the Script.Response routine to be called within the four event handler routines: Folder_OnMessageCreated, Message_OnChange, Folder_OnMessageDeleted, and Folder_OnTimer.

In the following code, for example, Script.Response is called if GetEventDetails fails. When this happens, the string "GetEventDetails failed." is written to the execution log.

' DESCRIPTION: This event is fired when a new message is posted in the folder.
Public Sub Folder_OnMessageCreated
 On Error Resume Next
 GetEventDetails
 If Err.Number = 0 Then 
    MakeResponseMessage()
 Else
    Script.Response = "GetEventDetails failed."
 End If
End Sub

Script.Response functions only in the four routines that correspond to events. It does not function in any other (supporting) routines in the Event Service script. But the F & M developers still wanted debugging functionality in those support routines. For example, in the following code, DebugReport is called to record any errors in the previous line, in which e-mail addresses are added to the Recipients collection of a message object:

Private Sub SendApproverForm()
   msgResponse.Recipients.AddMultiple ApproverEmail,cdoTo
   Call DebugReport("MessageResponse.Recipients.Add",True)

How DebugReport Works

DebugReport uses the global g_bsrDebug variable to store text, including error text. While the script is running, DebugReport adds text to the existing string, and finally displays it at the end of the event (not supporting) routine.

For example, in Folder_OnMessageDeleted, DebugReport is called twice. The first time, it simply writes the string "LitCrit_Review - OnMessageDeleted" to the log file. In this call, "False" means that no error is expected; it simply shows what part of the code has just been executed.

Call DebugReport("LitCrit_Review - OnMessageDeleted",False)

The next time it is used is immediately after the instantiation of the server-side Critique COM component:

Set objCritique = CreateObject("LitCrit.Critique")
If Not IsObject(objCritique) Then
   Call DebugReport("Create LitCrit Object",True)

In the preceding code, the value passed for boolErrChkFlag is True, indicating that this call might fail, and if so to generate an error report. To see how this is done, see Code of DebugReport.

Finally at the end of Folder_OnMessageDeleted, this line appears:

Script.Response = g_bstrDebug

Because this line appears in one of the four event routines, Script.Response can execute, and the contents of the g_bstrDebug string are written to the log file.

Code of DebugReport

This is the complete code of the DebugReport subroutine from LitCrit_Agent.asp:

'--------------------------------------------------------------------
'Desc: Simple Debugging Function
'Parameters: String Text, Boolean ErrorFlag
'--------------------------------------------------------------------
Private Sub DebugReport(bstrParm,boolErrChkFlag)
  If boolErrChkFlag = True Then
     If Err.Number <> 0 Then
        g_bstrDebug = g_bstrDebug & bstrParm & " Failed: " & Hex(Err.Number) & _
                      " -- " & Err.Description & vbCrLf
        Err.Clear
     End If
  Else
     g_bstrDebug = g_bstrDebug & bstrParm & vbCrLf
  End If
End Sub