Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scheduled agent 1

Status
Not open for further replies.

IreneKitty

Technical User
Jul 9, 2004
9
SG
Hi.

This scheduled agent used to run properly. However, it begins to give these errors recently. Can anyone advise?

23/06/2004 09:19:11 AMgr: Agent ('Reminder' in 'DEV\PRS\PRS.nsf') printing: PRS DB -- Error Number 204 Error 4000: Notes error: You are not authorized to use the server
23/06/2004 09:19:11 AMgr: Agent ('Reminder' in 'DEV\PRS\PRS.nsf') message box: Error 4000: Notes error: You are not authorized to use the server

Line: 204
 
Hello,

I would try and sign the Agent with the Server ID. Might not be the safest, but you can see if it's related to the current ID it's running under.

Rgds,

John
 
Hi John.

Had tried to recreate the agent using the server ID but still have the same error. No idea what has caused the agent to stop running.
 
You have to try to remember what it is that has changed before the agent started logging errors.
If it worked before, and no longer does now, then something has to have changed. You must find out what it is, then check the code to see why that something has an impact.
Failing that, you'll have to do a manual run with remote debugging - but that might not work if you use your personal (or anyone else's) credentials.
What I always do for a scheduled agent is to embed some logging code. I usually have a log database (not the server log), or I record the log into a log view in the database where the agent runs from.
In the log, I indicate all variable values as they occur, all status values (is db open and such), and generally where the code is going. Of course, I also code a switch to turn off logging when it is no longer useful, so as not to burden the db any more than necessary.
This process has been invaluable for me many times, as issues such as this always end up rearing their ugly little head. Only when you can trace what is going on after the fact can you pinpoint where the error takes place, which gives you a chance at correcting it.
It takes a bit of time to implement, but it saves a lot a guesswork and headaches.
If you want my logging code, just say so and I'll post it here.

Pascal.
 
Thank you very much! Can I have the code please? I would get my developer to put in the agent.
 
Okay, here it is.
Bear in mind that this code is my personal solution to the lack of easy-to-use debugging tools from Lotus.
Code:
'log_code: 

Option Public
Dim loglines As Long

Sub log_init(s As NotesSession,db As notesdatabase,logdb As notesdatabase,logflag As Integer,logdoc As NotesDocument,doclog As NotesRichTextItem,procname As String,logdomain As String)
	
	On Error Goto errcode
	If logflag Then
		Call addlogheader(doclog,procname)
	Else
		Set logdb = s.GetDatabase(db.server,[i]logdbpath[/i],False)
		If logdb.IsOpen Then logflag = True Else logflag = False
		If logflag Then
			Set logdoc = logdb.createdocument
			logdoc.form ="Log"
			logdoc.status="started"
			logdoc.domain=logdomain
			logdoc.process=procname
			logdoc.user=s.username
			Set doclog = New notesrichtextitem(logdoc,"body")
		End If
	End If
	Goto endcode
errcode:
	Print "Log creation impossible - " & Error$
	Resume endcode
endcode:
End Sub
Sub addlogline(doclog As NotesRichTextItem,msgdata As String)
	Static i As Integer
	
	msgdata = Time$ & " " & msgdata
	Call doclog.AppendText(msgdata)
	i=i+1
	loglines = loglines + 1
	If i>69 Then
		i = 0
		Call doclog.AddNewline(1,True)
	Else
		Call doclog.addnewline(1,False)
	End If
End Sub
Sub addloglinevalue(doclog As NotesRichTextItem,msgdata As String,itemvalue As Variant)
	Dim stritem As String
	
	If Datatype(itemvalue) = 8 Then
		stritem = itemvalue
	Else
		stritem = Str(itemvalue)
	End If
	msgdata = msgdata & stritem
	Call addlogline(doclog,msgdata)
End Sub
Sub wraplog(logdoc As notesdocument,doclog As NotesRichTextItem)
	logdoc.status="Finished"
	Call addlogline(doclog,"End of process")
	Call logdoc.ComputeWithForm(False,False)
	Call logdoc.save(True,False,True)
End Sub

Sub addlogheader(doclog As NotesRichTextItem,procname As String)
	Call addlogline(doclog,"******************************************************************")
	Call addlogline(doclog,procname)
	Call addlogline(doclog,"******************************************************************")
End Sub
Function checkloglinecount As Long
	checkloglinecount = loglines
End Function
So, with this very small library, what do you get ?
First, I must explain how to use this library.
The principle of use is as follows : you have a piece of code that you wish to trace. Use the Include statement to include this library as reference, then declare some variables in the Declarations portion of your library.
These are the variables you need to declare :


'log code requirements
Dim logdb As notesdatabase
Dim logdoc As NotesDocument
Dim logmsg As String
Dim logflag As Integer
Dim doclog As notesrichtextitem

With these global variables, you are ready to start tracing your code.

At the start of your code, you need to "open" the log. You do this by writing this line :
Code:
Call log_init(session,db,logdb,logflag,logdoc,doclog,"Code title",LogDomain)
This opening declaration allows you to recover three things :
- a boolean (LogFlag) that tells you that the trace is enabled,
- a notesdocument object (LogDoc) that will hold the trace information, and
- a notesrichtextitem (DocLog), in which you write the trace

Now you need to start including trace data.
It is up to you to decide how far you want to go, but whenever an important branch occurs, I include a line like this :
Code:
If logflag Then Call addlogline(doclog,"trace message here")

Also, when I want to trace a variable's value at some point, I use this :
Code:
If logflag then Call addloglinevalue(doclog,"Variable  name ",variablevalue)

Once you have appropriately inserted your trace code, you must use wraplog to finish your trace.
At this point, a line like this is needed :
Code:
Call wraplog(logdoc,doclog)
If, for some reason, you want a line count, you can use checkloglinecount, a function that returns a long value with the number of lines written in the log. Do it before wrapping up, though.

You will notice that log_init subroutine looks for a log database. It is up to you to set one up before doing a trace, or rewrite that portion to just open a log document in the current database.
Also, there is a useless little function to include a header in the trace, in case of need.

There, that should just about wrap up the explanation. It is not an easy solution, but implementing this trace function has saved me months of headaches and questions.

I hope it will help you.

Pascal.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top