Schedule agent generating inconsistent files

Hello All,

I have a scheduled agent which runs on the nab every night and generates a file. The problem I’m having is that once in a month, it skips around 1000-2000 document out of a total of 8000 documents. Could it be anything to do with view indexing or any such activity. My code is:

Sub Initialize

' This module builds a pipe-delimited text file

' Modified 2 Jul 04 -	Uses Database Configuration document to determine details

Dim session As New NotesSession

Dim nabdb As NotesDatabase

Dim db As NotesDatabase

Dim nabview As NotesView

Dim allentries As NotesViewEntryCollection

Dim entry As NotesViewEntry

Dim configdoc As NotesDocument

Dim memo As NotesDocument

Dim body As NotesRichTextItem

Dim administrator As Variant	

Dim nabserver As Variant

Dim values As String

Dim valuearray As Variant

Dim filename As Variant

Dim filenum As Integer

Dim count As Integer

Dim errorquantity As Integer



On Error Goto AnnounceError



Set db = session.CurrentDatabase

Set configdoc = db.GetProfileDocument ( "Database Configuration" )

nabserver = configdoc.GetItemValue ( "Server" )

filename = configdoc.GetItemValue ( "Filename" )

’

Set nabdb = session.GetDatabase ( "", "names.nsf" )

If Not nabdb.IsOpen Then

	Call nabdb.Open ( "", "" )

End If

’

Set nabview = nabdb.GetView ( "AllUsers" )

Set allentries = nabview.AllEntries

Set entry = allentries.GetFirstEntry ( )



filenum = Freefile ( )

Open filename (0) For Output As filenum

count = 0

errorquantity = 0

’ build an output record for each user and put it into the file

While Not entry Is Nothing

	count = count + 1

	values = entry.ColumnValues (0)

	Print #filenum, Trim$ ( values )

	Set entry = allentries.GetNextEntry ( entry )

Wend

Print Count

Finish:

’ Set memo = db.CreateDocument

’ memo.Subject = “Userlist submitted to OID”

’ memo.Principal = “Portal Utilities Database”

’ Set body = memo.CreateRichTextItem ( “Body” )

’ Call body.AppendText( “There were " & allentries.Count & " in the view” )

’ Call body.AddNewline (1)

’ Call body.AppendText( count & " of these were processed." )

’ Call body.AddNewline (1)

’ If errorquantity > 0 Then

’ Call body.AppendText( errorquantity & " were errors, but were corrected and included in this export." )

’ Call body.AddNewline (2)

’ End If

’ Call body.AppendText( “This is the output file…” )

’ Call body.AddNewline (1)

’ Call body.EmbedObject ( EMBED_ATTACHMENT, “”, filename (0), “Output” )

’ determine the database administrator

’ administrator = configdoc.GetItemValue ( “Administrator” )

’ Call memo.Send ( False, administrator)

Close #filenum

Exit Sub

AnnounceError:

If entry Is Nothing Goto Finish

errorquantity = errorquantity + 1

valuearray = entry.ColumnValues (0)

values = valuearray (0)

Resume Next

End Sub

TIA,

Ki

Subject: Schedule agent generating inconsistent files

If your agent runs fine 29 days out of 30, then it probably isn’t your code.

I would make sure the agent runs at a slow period - say 4:00 am, not the default time of 1:00 am when the server is often quite busy doing design tasks, updall, etc.

Also, try adding view.Refresh at the start of your code.