Example 1: Does not require a pre-existing backup in order to function
This script agent moves ANY document that does not exist in a folder to the Inbox. This means that some documents that only exist in the All Documents view will also be moved, including Profile documents and Organizer Setup documents. When finished, select these documents and choose Actions --> Remove From Folder.
NOTE 1: Deleting a document from any view or folder deletes it entirely from the database.
NOTE 2: It is very important to make a backup of your mail file before using it.
* This script builds an array of documents that are included in a folder. It then compares each document in the All Documents view to each document in the array.
* If the script finds one, it breaks out and continues onto the next document.
* If it reaches the end of the array, then it hasn't found a match and the document is moved to the Inbox folder.
'*************************************************************************
Sub Initialize
Dim s As New notessession
Dim db As notesdatabase
Dim fDoc As NotesDocument ' Document in folder
Dim ad As notesview ' All Documents view
Dim aDoc As notesdocument ' document in All Docs view
Dim fUNID() As String ' array of UNID's of docs in folders
Dim i As Integer ' UNID array index
Dim deldate As notesitem
Dim Chair1 As notesitem
i =0
Set db = s.CurrentDatabase
Redim fUNID(0)
' Build UNID array by looping through folders, then their documents
Forall view In db.views
If view.IsFolder And Not view.Name=("($All)") Then
Set fDoc = view.GetFirstDocument
While Not fDoc Is Nothing
Redim Preserve fUNID(i)
fUNID(i) = fDoc.UniversalID
i=i+1
Set fDoc = view.GetNextDocument(fDoc)
Wend End If End Forall
' Loop through docs in the All Documents view and compare UNIDs to each doc in the array
Set ad = db.GetView("($All)")
Set aDoc = ad.GetFirstDocument
While Not aDoc Is Nothing
i = 0
Do While i <= Ubound(fUNID)
If fUNID(i) = aDoc.UniversalID Then
Exit Do End If
i = i + 1 Loop
Set deldate = adoc.getfirstitem("delivereddate")
Set Chair1 = adoc.getfirstitem("CHAIR")
If i > Ubound(fUNID) And Not deldate Is Nothing And Chair1 Is Nothing
Then Call adoc.PutInFolder( "($Inbox)") End If
Set aDoc = ad.GetNextDocument(adoc) Wend
End Sub
Example 2: Requires a pre-existing backup mail file which has the Inbox populated
This agent cycles through the documents found in the backup mail files's Inbox, then locates the same documents in the current mail file and moves them into the Inbox. If a document from the backup mail file is not found in the current mail file then the agent skips to the next document.
* The agent should be designed to act on a Target of "None".
* The current mail file should have an existing Inbox folder which was created by refreshing or replacing the mail file's design.
* You must edit the code below to specify:
-- the backup mail file in the call to the GetDatabase method which sets the variable "backup".
-- the current mail file in the call to the GetDatabase method which sets the variable "db".
'*************************************************************************
(Declarations)
%INCLUDE "lsxbeerr.lss"
Sub Initialize
On Error lsERR_NOTES_BAD_UNID Goto processError
Dim s As New NotesSession
Dim db As NotesDatabase
Dim backup As NotesDatabase
Dim doc As NotesDocument
Dim bdoc As notesdocument
Dim view As NotesView
Set db = s.GetDatabase("Server/Org","mail.nsf")
Set view=db.GetView("($Inbox)")
If Not view Is Nothing Then
Set backup = s.GetDatabase("Server/Org","backup.nsf")
Set view = backup.GetView("($Inbox)")
Set bdoc= view.GetFirstDocument
While Not(bdoc Is Nothing)
Set doc = db.GetDocumentByUNID(bdoc.UniversalID)
Call doc.PutInFolder( "($Inbox)" ) getNextDocument:
Set bdoc = view.GetNextDocument(bdoc) Wend
Exit Sub
processError:
Resume getNextDocument Else
Messagebox "The mail file must have a Inbox folder in order to proceed. Refresh the design of the mail file and then rerun the agent" End If
End Sub