Hi Experts,
I have found a error message when the below schedule LS code run for archive the documents.
Err: 4432: Entry is no longer in view: (ECM Docs to Archive) line: 32
Code :
Option Public
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim archivedb As NotesDatabase
Set db = session.CurrentDatabase
On Error GoTo errorhandler
'Open archive db
filename$ = Strleft(db.Filename, “.”) & “_” & Format$(Today, “yyyymm”) & “.nsf”
Set archivedb = New NotesDatabase(db.Server, "mailECM" & filename$)
'Get all the docs within the "archive" view as these have the "IBMAfuArchivingDate" field set
Dim view As NotesView
Dim collection As NotesViewEntryCollection
Dim entry As NotesViewEntry
Dim doc As NotesDocument
Dim newdoc As NotesDocument
Dim ecmarchived As NotesDateTime
'Set the archive date to be 21 days ago
Dim datetoarchive As New NotesDateTime(Now)
Call datetoarchive.Adjustday(-21)
Set view = db.GetView("ECMArchiveDocs")
Set collection = view.AllEntries
MsgBox collection.Count
'Loop through all docs in the collection and copy them to the archive db and then delete from this db
For x = 1 To collection.Count
Set entry = collection.Getnthentry(x)
Set doc = entry.Document
Set ecmarchived = New NotesDateTime(doc.IBMAfuArchivingDate(0))
time_diff# = datetoarchive.TimeDifferenceDouble(ecmarchived)
If time_diff# > 0 Then 'Doc archived over a week ago
Set newdoc = doc.CopyToDatabase(archivedb)
Call doc.Remove(true)
End if
Next
End
errorhandler:
error_text$ = Err & ": " & Error & " line: " & Erl
Print error_text$
Dim maildoc As NotesDocument
Set maildoc = db.CreateDocument
With maildoc
.Form = "Memo"
.Subject = "CPA ECM Archive error: " & db.Title
.Body = |The "Arhive - docs weekly" agent has errored as follows:
| & error_text$ & |
Within the following database:
| & db.Server & “: " & db.Filepath & " (” & db.Title & “)”
End With
'Call maildoc.Send(False, "support@Applicable.com")
Call maildoc.Send(False, "xyz@xyz.com")
end
End Sub
Thanks !!!
Subject: Entry is no longer in view: (View Name)
-
Use the debugger and tell what line of code is causing the error.
-
Use Option Declare, and declare all your variables. That will help you find many errors.
-
I would recommend not using GetNthEntry(), use GetFirstEntry/GetNextExtry() instead. Don’t use a for-loop to get the entries.
-
Since you are working on documents, you could use GetFirstDocument/GetNextDocument() instead.
-
In your code, you move the document, delete the document, and then you are trying to get the next document (through getting the next entry) and that won’t work, since the document it need to get teh next document has been deleted.
-
When you post code, you can remove everything not relevant, like the mail notification part. You can replace it with a comment, indicationg what you do. Or if you would break out certain code into functions, it would be easier to read as well.
What you should do is something like this:
Set doc = col.GetFirstDocument
Do Until Not doc Is Nothing
'*** Do your archiving/copying here
set deldoc = doc
Set doc = col.GetNextDocument(doc)
Call deldoc.Remove(True)
Loop
Depending on the number of documents, I would even put the deletion outside the loop:
Dim deldoc List As NotesDocument
Set doc = col.GetFirstDocument
Do Until Not doc Is Nothing
'*** Do your archiving/copying here
set deldoc(doc.UniversalID) = doc
Set doc = col.GetNextDocument(doc)
Loop
ForAll d in deldoc
Call d.Remove(true)
End Forall
Subject: RE: Entry is no longer in view: (View Name)
Hi Karl,
Thnaks for your responce. I do all changes as you suggested.
Error which I have faced “Entry is no longer in view: (View Name)” occur in the way of coding or declaration or use get nth entry or any other.
Error Line : Set doc = entry.Document
This code is working fine and archive the documents but only one time(previous schedule) its propmpt this error.
I do the change as you mentioned but can you please tell me the actual reason of this error.
Thanks Karl again.
Subject: RE: Entry is no longer in view: (View Name)
If you are iterating through documents in a view, and your actions within the loop have the potential to remove documents from that view, you need to pick up the next document BEFORE the processing starts. For archiving, I use the following structure:
Set docCurr = vwWhatever.GetFirstDocument
Do Until DocCurr Is Nothing
Set docNext = vwWhatever.GetNextDocument(docCurr)
'Processing here, with option on deleting docCurr or otherwise changing it such that it no longer appears in vwWhatever
Set docCurr = docNext
Loop
Subject: RE: Entry is no longer in view: (View Name)
When I pick the next document before doing the processing,then its prompt me the error message “Entry not found in Index(view name)”.
Thanks
Subject: RE: Entry is no longer in view: (View Name)
Post your code, I don’t think you are doing it right. Mark posted perfectly fine code, and I use the same method myself (wrote some like that just last week, as a matter of fact).