Domino Code Fragment

Code Name*
Creating a New and Modified
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.145.97.248
Description*
Creating a New and Modified
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
Exercise Title : Media Search ( New and Modified )

Where : Agent

Solution :

Sub Initialize
'-- For each Query document selected by the Agent :
'-- This script will perform searches of multiple Notes databases based on the criteria in the
'-- queryText field in the current document and return the results as a one newsletter response document
'-- to the original query document

'-- Get unprocessed document collection from Current Database
Dim Session As New NotesSession
Dim currentdb As NotesDatabase
Set currentdb = Session.CurrentDatabase

Dim unprocessed As NotesDocumentCollection
Set unprocessed = currentdb.unprocesseddocuments

'-- 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"

'-- Iterate through collection
Dim doc As NotesDocument
Set doc = unprocessed.getfirstdocument

Do While Not (doc Is Nothing)

'-- Process Media Documents Only
If doc.form(0) = "Media Search" Then

'-- Get the search string from the document
Dim FTQuery As String
FTQuery = doc.QueryText(0)

'-- Search all databases (defined) by array
For i = 0 To 2

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

'-- If database is open then search it
If db.IsOpen Then

Call db.UpdateFTIndex(True)

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

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

If collection.count > 0 Then

'-- Create Newsletter object
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
Dim Resultsdoc As NotesDocument
Set Resultsdoc = newsletter.FormatMsgWithDoclinks(currentdb)

'-- 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 : " & collection.count & " matches found."

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

'-- Label the NEW Response Document as Processed
Call session.UpdateProcessedDoc(ResultsDoc)

End If

End If

Next i

End If

'-- Label the Query Document
Call session.UpdateProcessedDoc(doc)

'-- Get next document
Set doc = unprocessed.getnextdocument(doc)

Loop

End Sub