Why this agent dont work?

Dim Session As New NotesSession Dim db As NotesDatabase

Dim db2 As New NotesDatabase( "Server", "Database" )

Dim ws As New NotesUIWorkspace

Dim doc As NotesDocument

Dim doc2 As NotesDocument

Dim rti As NotesRichTextItem

Dim rtnav As NotesRichTextNavigator

Dim rtrange As NotesRichTextRange

Dim iCount As Integer

Dim vSplit As Variant

Dim NewDoc As NotesDocument

Dim collection As NotesDocumentCollection



Set db = Session.CurrentDatabase

Set collection = db.UnprocessedDocuments

Set doc = collection.GetFirstDocument()



While Not(doc Is Nothing)

	

	

'Set doc = ws.CurrentDocument.Document

	Set rti = doc.GetFirstItem("Body")

	Set rtnav = rti.CreateNavigator

	Set rtrange = rti.CreateRange

	

	

	Set session = New NotesSession

	

	Set Newdoc = New NotesDocument( db )

	

	Set doc2 = New NotesDocument ( db2 )

	doc2.Form = "MainForm"

	Newdoc.Form = "Memo"		

	

	If rtnav.FindFirstElement(RTELEM_TYPE_TEXTRUN) Then

		Do

			iCount = iCount + 1

			

			Call rtrange.SetBegin(rtnav)

			

			vSplit = Split(rtrange.TextRun, Chr(9))

			

			If icount = 2 Then

				

				doc2.ReferenceNum = vSplit(Ubound(vSplit))

				

			Elseif icount = 3 Then

				

				doc2.Title = vSplit(Ubound(vSplit))

				

			Elseif icount = 4 Then

				

				doc2.FirstName = vSplit(Ubound(vSplit))

				



				

			End If

			

		Loop While rtnav.FindNextElement(RTELEM_TYPE_TEXTRUN)

		

		Call doc2.Save(False,True)

	End If

	

	Call session.UpdateProcessedDoc( doc )

	Set doc = collection.GetNextDocument(doc)	

Wend

All it does is to mail body contents to another database into specific fields…

Any help would me much appreciated

Regards

Subject: Why this agent dont work?

If this is a scheduled agent then you can not use the ui classes so try removing the line Dim ws As New NotesUIWorkspace.

Subject: RE: Why this agent dont work?

Thanks a lot Matt,

I remove the line but is still does not work.Also i cannot debug this code…

Regards

Subject: RE: Why this agent dont work?

You can debug scheduled agents by using error handling routines that write output to a noteslog or using messagebox that will write to the console.

It is easier to get this working as a manual agent first as running it from the client you can step through it in the debugger. I would set it to run on selected documents and then amend the code slightly to get a handle on the selected documents in the view using notesuiview property Documents.

Subject: RE: Why this agent dont work?

Thanks all of you for the answers.I check and i reply you asap

Subject: RE: Why this agent dont work?

Try to write “msgbox” statements in middle of the code.

Also, include error handler in the code -

on error goto errdesc '(this should be the first line in the agent after sub initialize)

at end before end sub, write this code -

exit sub

errdesc:

Print "Got error " & Error$ & " on line " & cstr(Erl)

use msgbox if you want to print to the domino server console -

msgbox "Got error " & Error$ & " on line " & cstr(Erl)

This would help you out finding what went wrong.

–Phani