IBM Support

Using a LotusScript agent to search all mail databases for a particular string

Technote (FAQ)


You need to search all Lotus Notes® mail databases for a particular string then copy all documents containing the string to a database. How can you use a LotusScript agent to accomplish this task?


The LotusScript code below is one way to search all mail databases for a particular string.

Notes about the agent design and usage:

  • This code is designed for an agent that can be created in a new mail database.
  • The agent is designed to run on event from the Action menu with a Runtime Target of None.
  • The agent searches all databases on the server (servername) under the 'mailpath' you specify and copies all relevant documents to the mail database where the agent resides.
  • For this agent to run, the mail files must be full text indexed. Full text indexes can be created for all mail databases by highlighting them in the Files tab of the Domino Administrator client and right-clicking -> Full Text Index… -> Create.

IMPORTANT NOTE: This sample script provided below illustrates one way to approach this issue. IBM Lotus Support will not be able to customize this code for a customer’s own configuration. While this code has worked in test environments, it is offered as a suggestion only, and is not something that Lotus supports further.

Dim session As New Notessession
Dim thisdb As NotesDatabase
Dim db As NotesDatabase
Dim pos As Integer
Dim servername As String
Dim mailpath As String
Dim mailowner As String
Dim searchstring As String
Dim doccol As NotesDocumentCollection
Dim doc As NotesDocument

'Indicate mail subdirectory name
mailpath = "mail\"
'Server name (in canonical format) or leave blank for local server/directory:
servername = ""
'Indicate the string to search for
searchstring = ""

Set thisdb = session.CurrentDatabase
Dim dbdir As New NotesDbDirectory(servername)
'Cycle through databases on the server
Set db = dbdir.GetFirstDatabase(DATABASE)
While Not db Is Nothing
'Skip databases which you don't have access to
On Error 4060 Goto Error4060
'Check to see if this database is in the mail directory
pos = Instr(db.FilePath, mailpath)
If pos = 1 Then
Call db.Open(servername, db.FilePath)
'Search for documents using search string
Set doccol = db.FTSearch(searchstring,0)
Set doc = doccol.GetFirstDocument
While Not doc Is Nothing
'Copy all documents found to current database
Call doc.CopyToDatabase(thisdb)
Set doc = doccol.GetNextDocument(doc)
End If
Set db = dbdir.GetNextDatabase()
Exit Sub
'If the code reaches here then the user does not have access rights.
Resume GetNextDb

Document information

More support for: IBM Domino Designer

Software version: 6.5, 7.0, 8.0, 8.5

Operating system(s): Windows

Reference #: 1259256

Modified date: 04 January 2010