How to schedule the agent to run...Can someone test this code for me?

Hi, I am currently stuck with this code… It’s supposed to work, but for some reason, it’s not working… It can be scheduled at 5 minutes if you want to test it out. Below is the situation…

I just found out that my company has policy that we can schedule to run agent at 1 hour (60 minutes). I did set schedule for 1 hour, but received only one email so fart. So I don’t know if there is something wrong with this agent or the way I am setting up this agent. If you have time, can you check to see if this agent is able to run (schedule for 1 hour) on your system. If it does run fine on your system every 1 hour, then I guess that either I don’t set up properly.

===========================

Sub Initialize

Dim session As New NotesSession

Dim doc As NotesDocument

Dim db As NotesDatabase

Dim dc As NotesDocumentCollection

Dim view As NotesView

Dim vc As NotesViewEntryCollection

Dim entry As NotesViewEntry

Dim SendDoc As NotesDocument

On Error Goto Quit

Set db = session.CurrentDatabase

'Change this view to your view

Set view = db.GetView(“Mike Woo”)

Set vc = View.AllEntries

Set entry = vc.GetFirstEntry()

While Not entry Is Nothing

Set doc = entry.Document

Set SendDoc = New NotesDocument(db)

SendDoc.Form = “Memo”

SendDoc.Principal = “DB Admin”

'Change this email to your email

SendDoc.SendTo = “Mike.Woo@mycompany.com

SendDoc.Subject = “Testing agent”

Call SendDoc.Send(False)

doc.txtTicklerMailSent = “Yes”

Call session.UpdateProcessedDoc(doc )

Call doc.Save(True, True)

Set entry = vc.GetNextEntry(entry)

Wend

Exit Sub

Quit:

Msgbox Error & " at line: " & Erl

End Sub

===========================

thank you.

Mike Woo

Subject: How to schedule the agent to run…Can someone test this code for me?

Sorry to be so blunt, but did it ever occur to you that there was only one message to send in the example you gave?

Regards

Rolf Pfotenhauer

Subject: RE: How to schedule the agent to run…Can someone test this code for me?

Hi Rolf,

Thanks for the response. I don’t undertand your question, can you please rephrase that.

There is only one statement for printing:

SendDoc.Subject = “Testing agent”

The issue is: When I ran this agent for example, at 5:00 PM(at the time I scheduled this, click on run), so I received five emails (since there are five documents (rows) in the view) at 5:00 PM. If there is only 1 doc in the view, then I would receive only 1 email. I waited for another hour (due to scheduling this agent for an hour period), and I haven’t received any email since. And I thought that I would receive email(s) every hour or so, but nothing happens. However, I checked the log(by clicking on Tools ==> Log), it says that it the agent ran at 6:00 PM or so on…

I have made myself as the manager and am not sure how it might affect this.

I don’t have access to the designer at home, so this is all I know at this point.

Thank you.

Mike Woo

Subject: Perhaps because [doc.txtTicklerMailSent = “Yes”] removes the document from the view?

Subject: RE: Perhaps because [doc.txtTicklerMailSent = “Yes”] removes the document from the view?

Hi Bill,

thanks for the response. It seems it doesn’t work, too

You will find below is the trigger and more information relates to the code and the agent log.

Agent window: First tab:

Shared

Options: Store search in search bar menu

Store highlights in document

Trigger: On schedule

Runtime: More than once a day

Target: All new & modified documents

Schedue:

1 hour (or 5 minutes)

All day

Where the agent runs

Run on: server which this agent and database are currently on.

Below is the updated code for it:

Dim db As NotesDatabase

Dim view As NotesView

Dim vc As NotesViewEntryCollection

Dim entry As NotesViewEntry

Dim doc As NotesDocument

Dim SendDoc As NotesDocument

=========================

Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim dc As NotesDocumentCollection

Dim view As NotesView

Dim vc As NotesViewEntryCollection

Dim entry As NotesViewEntry

Dim doc As NotesDocument

Dim SendDoc As NotesDocument

Dim nrtiNotice As NotesRichTextItem

Dim agentlog As NOTESLOG

Dim iDocs As Integer

On Error Goto Quit

iDocs = 0

Set agentlog = New NOTESLOG( “DBTesting” )

Call agentlog.OPENAGENTLOG

Call agentLog.LogAction("Started: " & Time$())

Set db = session.CurrentDatabase

'This is one of the views in my db, you can modify this view according to your db

Set view = db.GetView(“Mike Woo”)

Set vc = View.AllEntries

Set entry = vc.GetFirstEntry()

While Not entry Is Nothing

iDocs = iDocs + 1

Set doc = entry.Document

'ListName is the text field editable on the form.

Call agentLog.LogAction("ListName: " & doc.ListName(0) & “;”)

Print("ListName: " & doc.ListName(0) & “;”)

Set SendDoc = New NotesDocument(db)

Set nrtiNotice = New NotesRichTextItem(SendDoc, “Body”)

Call nrtiNotice.AddNewLine(1)

Call nrtiNotice.AppendText("ListName: " & doc.ListName(0) & “;”)

Call nrtiNotice.AddNewLine(1)

Call nrtiNotice.AppendText("Sent: " & Time$() & “;”)

Call SendDoc.ReplaceItemValue(“Form”, “Memo”)

Call SendDoc.ReplaceItemValue(“SendTo”, “Mike.Woo@mycompany.com”)

Call SendDoc.ReplaceItemValue(“Subject”, "DBTesting: " & Time$())

Call SendDoc.Send(False)

Call doc.ReplaceItemValue(“txtTicklerMailSent”, Time$())

Call doc.Save(True, True)

Set entry = vc.GetNextEntry(entry)

Wend

Call agentLog.LogAction("Ended: " & Str(iDocs))

If Not ( agentLog Is Nothing ) Then

Call agentlog.CLOSE

End If

Exit Sub

Quit:

Msgbox Error & " at line: " & Erl

End Sub

================================

Started running agent ‘DbTesting’ on 06/17/2004 10:02:52 AM

Running on new or modified documents: 19 total

Found 19 document(s) that match search criteria

06/17/2004 10:02:52 AM: Started: 10:02:52 AM

06/17/2004 10:02:52 AM: ListName: XXXXXX;

06/17/2004 10:02:52 AM: ListName: XXXXXX;

06/17/2004 10:02:52 AM: ListName: XXXXX;

06/17/2004 10:02:52 AM: ListName: XXXXX;

06/17/2004 10:02:52 AM: ListName: XXXXX;

06/17/2004 10:02:52 AM: ListName: XXXXX;

06/17/2004 10:02:52 AM: ListName: XXXXX;

06/17/2004 10:02:52 AM: ListName: XXXXX;

06/17/2004 10:02:52 AM: Ended: 8

Ran LotusScript code

Done running agent ‘DbTesting’ on 06/17/2004 10:02:52 AM

where XXXX is name of the document.

I set it for 5 minutes (or 10 minutes, or 1 hour), it didn’t work, too. That’s the result of five minutes scheduling.

I am not sure because of the server or the way I set up the agent or because of the logic in the agent.

Mike Woo.

Subject: How to schedule the agent to run…Can someone test this code for me?

I tried to run the code you gave first and it is worked if it is stil not working check the properties of this agent.

Subject: RE: How to schedule the agent to run…Can someone test this code for me?

Hi Ozcan,

I found out that the email was blocked by the server after the first time. That means email can be sent out only one time since this was the development server. Server team is “a wax team”!!!

I am trying to find out away of “cracking down” this. How can I write up the little script to replace the setting in the agent. I am thinking of not using agent anymore, instead creating a lotus script and let it runs 24 hours per day, and I don’t know how to do that yet. Do you have any idea?

Mike Woo

Subject: How to schedule the agent to run…Can someone test this code for me?

A lot of useful info here:http://www-10.lotus.com/ldd/46dom.nsf/7e6c7e584a76331b85256a46006f083e/574c99ccb345839185256976004e811e?OpenDocument