Examples: GetDocumentByID method
- This script gets the document in the current database for which
the note ID is 000021CA, if such a document exists.
Sub Click(Source As Button) Dim session As New NotesSession Dim db As NotesDatabase Dim doc As NotesDocument Set db = session.CurrentDatabase Set doc = db.GetDocumentByID( "000021CA" ) If doc Is Nothing Then Messagebox("Document not found") End If End Sub
- This sub takes two string arrays and a NotesDatabase as parameters.
The elements of each array contain valid NoteIDs representing documents
in the NotesDatabase. The sub finds the NoteIDs that are present in both arrays,
uses GetDocumentByID to find the corresponding documents in the database,
and places a link to each document into a rich-text field of a new
document called resultDoc.
Sub mergeSearch( arrayA As Variant, arrayB As Variant, _ db As NotesDatabase ) Dim doc As NotesDocument Dim resultDoc As NotesDocument Dim rtitem As NotesRichTextItem Set resultDoc = New NotesDocument( db ) Set rtitem = New NotesRichTextItem( resultDoc, "Body" ) Forall noteIDa In arrayA Forall noteIDb In arrayB If (noteIDa = noteIDb) And (noteIDa <> "") Then Set doc = db.GetDocumentByID( noteIDa ) Call rtitem.AppendDoclink( doc, _ doc.Subject( 0 ) ) End If End Forall End Forall resultDoc.Subject = _ "Here's the results of two searches" Call resultDoc.Send( False, "Anne Mackinnon" ) End Sub
You could use the preceding sub to create a "newsletter" document that contains links to other documents that match two separate searches.
For example, when the following script calls the mergeSearch sub, Anne Mackinnon receives an e-mail memo containing links to documents in the current database that contain the word "wheels," have "bicycle" in the Subject item, and were created after January 20, 1995. The script performs two searches, constructs an array of NoteIDs representing the documents of the two resulting collections, and calls mergeSearch to do the rest.
Sub Initialize Dim session As New NotesSession Dim db As NotesDatabase Dim dateTime As NotesDateTime Dim collectionA As NotesDocumentCollection Dim collectionB As NotesDocumentCollection Dim docA As NotesDocument Dim docB As NotesDocument Dim arrayA( 1 To 10 ) As String Dim arrayB( 1 To 10 ) As String Set db = session.CurrentDatabase Set dateTime = New NotesDateTime( "01/20/95" ) Set collectionA = db.FTSearch( "wheels", 10 ) Set docA = collectionA.GetFirstDocument() Set collectionB = db.Search _ ( "@Contains( Subject; ""bicycle"" )", dateTime, 10 ) Set docB = collectionB.GetFirstDocument() For i = 1 To collectionA.Count arrayA( i ) = docA.NoteID Set docA = collectionA.GetNextDocument(docA ) Next For j = 1 To collectionB.Count arrayB( j ) = docB.NoteID Set docB = collectionB.GetNextDocument(docB) Next Call mergeSearch( arrayA, arrayB, db ) End Sub