Domino Code Fragment

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

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 one newsletter response document
'-- to the original query document

'-- 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 document
Dim session As New NotesSession
Dim currentdb As NotesDatabase
Set currentdb = session.currentdatabase

'-- Create a new document to contain all newsletter document information from all searches

Dim ResultsDoc As NotesDocument
Set ResultsDoc = New Notesdocument(currentdb)

'-- Working Newsletter document reference for each database
Dim workdoc As NotesDocument

'-- Search all databases, creating ONE newsletter response document
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

'-- Keep count of total matches
totalMatches = totalMatches + collection.count

Set newsletter = New NotesNewsletter(collection)

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

'-- Create Newsletter document
Set workdoc = newsletter.FormatMsgWithDoclinks(currentdb)

'-- Copy the work document into the final results document (which will hold
'-- the information from all newsletters for each database searched).
Call workDoc.CopyAllItems(ResultsDoc)

End If

Next i

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

'-- Set Form name and Title
ResultsDoc.Form = "Media Search Results"
ResultsDoc.Title = "Search Results : " + Str$(totalMatches) + " matches found."

'-- Save the newsletter document

Call ResultsDoc.save(True,True)

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

End Sub