View.entrycount not working

I have the following code to count the number of documents is a view. If the number exceeds 24 it should email me a message. This is ensure another scheduled agent in running against this view. Even though the view is empty, the counting agent is reporting back that there are over 1000 documents in the view. If you run the agent manually, it confirms that there are indeed no documents in the view.

Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim view As NotesView

Dim totalcount As Integer

Set db = session.CurrentDatabase

Set view = db.GetView("repFromCustomer")



totalcount = view.EntryCount



If totalcount >24 Then

	Set doc = New NotesDocument( db )

	Set rtitem = New NotesRichTextItem(doc, "Body" )

	Call rtitem.AddNewLine( 1 )

	Call rtitem.AppendText("Check Ironport Replies from Customer's view" )

	Call rtitem.AddNewLine( 1)

	Call rtitem.AppendText("Too many docs in the view" )

	Call rtitem.AddNewLine( 1)

	Call rtitem.AppendText("Number of entries = " + Str(totalcount))

	

	

	doc.Form = "Memo"

	doc.SendTo = "Jon Doody"

	doc.Subject = "Ironport Reply Memos  - 25 or more"

	Call doc.Send( False )

	

End If

End Sub

Any ideas why, when run manually it works, but when run on server shedule it claims there are over 1000 docs in the view?

The agent runtime is set to “All new & modified documents”.

Subject: view.entrycount not working

You could try this:totalcount = view.AllEntries.Count

But I suspect there are readers fields on the documents, so you can not see any documents, but the server sees all the documents, for all users.

Subject: RE: view.entrycount not working

Thanks! I’ll give that a try!