Script Library Issue

For a product that just turned 21, one would expect that all childhood issues were gone. Of course, I am (for now) stuck with a 17 year old slightly temperamental teenager… Anyway, I just ran into a strange issue, related to classes and code inherited from other templates.

Template A contains a script library with a class I wrote, called "AgentLog". It is used to log information about agents running in different databases. So obviously the script library need to reside in each database where I want to do the logging. Let’s say there are two, based on Template B and C. In an attempt to be clever, I simply copied the script library from Template A to Template B and C, and answered "yes" on the question if I wanted to inherit changes when the code in Template A is changed.

I then add some calls to the script library in template B and C, and push the changes out. Everything works great. A week or two later, I decide that I want to add some more info to the logging. I add one public string variable to the class, add a reference to it in one method called Terminate() and add a new method called AddMessage(). The new code is marked in red.

Class AgentLog
Private session As NotesSession
Private logdb As NotesDatabase
Private logdoc As NotesDocument
Private running As Integer
Private tstart As Long  ‘ Ticks at start
Private tend As Long  ‘ Ticks at end
Private tps As Long  ‘ Ticks per second (normally 1000)
Private message As String  ‘ Text to store in log entry, e.g. number of docs processed
 Public Sub AddMessage(txt As String)
  Me.message = Me.message + txt
End Sub

Public Sub Terminate()
  Dim seconds As Integer
  If logdoc Is Nothing Then
   Exit Sub
  End If
  tend = Getthreadinfo( THREAD_TICKS )
  seconds = (tend – tstart) / tps
  Call logdoc.ReplaceItemValue("EndTime", Now() )
  Call logdoc.ReplaceItemValue("Seconds", seconds )
  Call logdoc.ReplaceItemValue("Message", message )
  If running = True Then ‘ Check if not terminated gracefully
   Call logdoc.ReplaceItemValue("Terminated", "Yes" )   
  End If
  Call logdoc.Save(True,True)
End Sub

Nothing special, right? I did not even modify New() at all. All this was done in anticipation of adding the additional logging later in Application B and C (based on the templates B and C). The updated Template A was put in production, and the next night the update process refreshed the design of Template B and C with the new code, and they in turn updated Application B and C.

Now the users suddenly got an error message when code using the script library was launched: "Type mismatch on external name: AGENTLOG". I tested it and got the same error. I decided to turn on the debugger to see where exactly it happened. And of course then it worked! Debugger turned off, error again. I recompiled all Lotusscript in the application, and it worked with no debugger on. I then recompiled all code in Template A, refreshed design of Template B and C and recompiled all code in Template B and C. Despite this, the next day we had the same problem…

Finally I ended up not linking the script library from Template A to Template B and C. I will just have to copy it over again every time I make a change to every template where I use it. Anyone got any ideas what the problem might be?.


Leave a Reply