Domino Code Fragment

Code Name*
Creating Newsletters
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.18.220.13.70
Description*
Creating Newsletters
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:

Exercise Title : FTSearch - Multiple Databases

Where : PushButton or Form Action

Solution :

Sub Click(Source As Button)

'-- This script will perform searches of multiple Notes databases based on the criteria in the
'-- queryText field and return the results as a newsletter response document
'-- to the original query document for each database searched

'-- Get the Front and Back End Documents
Dim ws As New NotesUIWorkspace

Dim uidoc As Notesuidocument
Set uidoc = ws.CurrentDocument

Dim doc As NotesDocument
Set doc = uidoc.document

'-- Save the query document
If uidoc.IsNewDoc Then Call uidoc.save

'-- This array hold the names of the Notes DBs from which we search
Dim dbpath(2) As String
dbpath(0) = "PGN2\Newstand\news1.nsf"
dbpath(1) = "PGN2\Newstand\news2.nsf"
dbpath(2) = "PGN2\Newstand\news3.nsf"

'-- Access the current database to store the newsletter documents
Dim session As New NotesSession
Dim currentdb As NotesDatabase
Set currentdb = session.currentdatabase


'-- Declare Newsletter Document Object Reference
Dim ResultsDoc As NotesDocument

'-- Search all databases, creating a newsletter response document for each
For i = 0 To 2

'-- Open the database and update the index
Dim db As New NotesDatabase("",dbpath(i))
Call db.UpdateFTIndex(True)

'-- Perform the Full Text Search, returning the results
Dim collection As NotesDocumentCollection
Set collection = db.FTSearch(doc.QueryText(0) ,0)

'-- If matches are found, create a newsletter object using the matching document collection.
If collection.count > 0 Then

Dim newsletter As New NotesNewsletter(collection)

'-- SubjectItemName is the field from the news db which provides the newsletter subject values
newsletter.SubjectItemName = "DisplayHead"
newsletter.DoScore = False
newsletter.DoSubject = True


'-- Create Newsletter response document
Set ResultsDoc = newsletter.FormatMsgWithDoclinks(currentdb)
ResultsDoc.Form = "Media Search Results"
ResultsDoc.Title = db.title + " : " + Str$(collection.count) + " matches found."

'-- Make the Newsletter document a response to the query document
Call ResultsDoc.MakeResponse(doc)

'-- Save the newsletter document
Call ResultsDoc.save(True,True)
End If

Next i

'-- Close the query document and Refresh the view
Call uidoc.close
Call ws.ViewRefresh

End Sub