Script Agent Log

I never was happy with the error line number, and I do not like writing to the
Notes Log because it takes ages to find info. concerning a certain date -
especially if the agent did not run or the log is purged after so many days.

I prefer having my own agent log and generating my own error line code. So, if
you want an Agent Log that tells you if the agent ran, if it was successful, or
when did it crash, as well as what it did, then read on. Oh, I forgot, you
better be willing to change your way of writing script agents (just a bit).

What I suggest is not a single piece of code that does the work for you. I
suggest every time you write a new agent to include the header info., the
AddLine function, and use it regularly and completely in the code you wish to
write.
Whenever you start a new Script agent, start by including this AddLine function
:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -

Sub addline(doclog As notesrichtextitem,msg As String)
Static counter As Integer
Dim flag As Integer

flag = False
msg = Time$ + " : " + msg
Call doclog.appendtext(msg)
counter = counter + 1
If counter > 25 Then
flag = True
counter = 0
End If
Call doclog.addnewline(1,flag)
End Sub

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -

This code adds a line of text to a RTitem, allowing for a paragraph marker
every 25 lines (to avoid the limitation on single paragraph size). The counter
is static, so you do not need to manage it.

Of course, this function can be included in a Script Library.
At the beginning of your script (Initialize section), you need to include the
following :

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
Dim db as notesdatabase
'logging variables
Dim logdoc As notesdocument
Dim doclog As notesrichtextitem
Dim logflag As Integer
Dim logmsg As String

On Error Goto errhandle
Set db = session.currentdatabase
'you may change these lines to read logflag = false if you wish to turn
off the logging - or better, use a Profile document to switch it without
changing the code.
Set logdoc = db.createdocument
If Not (logdoc Is Nothing) Then logflag = True
If logflag Then
logdoc.form = "Log"
logdoc.Process = "Your Process Name"
logdoc.starttime = Time
logdoc.status = "Crashed"
Set doclog = New notesrichtextitem(logdoc,"Log")
logmsg = "Notification process starting"
Call addline(doclog,logmsg)
Call logdoc.save(True,True)
End If
errstep = "0"
'put your script code here
'end of script code
logdoc.status = "Completed"
Goto endcode
errhandle:
logmsg = "Error has occured"
Call addline(doclog,logmsg)
logmsg = "Error occured at step " & errstep
Call addline(doclog,logmsg)
logdoc.status = "Failed"
Resume endcode
endcode:
If logflag Then
logmsg = "End of notification process"
Call addline(doclog,logmsg)
'include summary info here
' . . .
'end of summary info
logdoc.endtime = Time
Call logdoc.save(True,True)
End If

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -

So, what do we see in this code ? First, we can see that you are basically
writing the log. As I said, I'm not giving you a turnkey solution. Second, we
see that the log process is encapsulating the normal script algorythm. The log
document is created in the current database and records the start of the agent
(or event), what it does, and when and how it ends.

Of course, since you are writing it, you can add as many lines to the log as
you wish.

To give an example, imagine that you want to write a QuerySave event that
checks a field on the document and sends a message to a user whose name is in a
Profile document. Normally, you would write a code like this :

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -

Sub Querysave(Source As Notesuidocument, Continue As Variant)
'environment variables
Dim db As notesdatabase
Dim doc,profile,maildoc As notesdocument

Set profile = db.getprofiledocument("ApplicationProfile")
If doc.validfield = "YES" Then
Set maildoc = db.createdocument
maildoc.form = "Memo"
maildoc.subject = "Auto Notifcation"
maildoc.body = "The document " & doc.docID(0) & " has been authorized"
maildoc.sendto
This was first published in November 2000

Dig deeper on Lotus Notes Domino Administration Tools

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchDataCenter

SearchExchange

SearchContentManagement

Close