This tip shows you how to create a function that returns the top-level document in a response thread. If you design an application that allows users to create response documents, you may need a script that retrieves a value located in the top-level document. For example, a "Response to response" document may need a value from a "Main Topic" document.
The following function does this:
'This is a recursive function. It returns the main document at the top of a thread. Function GetParentDocument( doc As NotesDocument ) As NotesDocument If Not( doc.IsResponse ) Then Set GetParentDocument = doc Exit Function End If Dim note As NotesDocument Set note = doc.ParentDatabase.GetDocumentByUNID( doc.ParentDocumentUNID ) If note.IsResponse Then Set GetParentDocument = GetParentDocument( note ) Else Set GetParentDocument = note End If End Function
The following example shows you one way to use this function. In this example, you have a database containing project documents and several "Response to response" documents. When a user closes a response document, the application should notify the sales manager. Define the manager's name on the Project document. Place the following code in the Queryclose event in a Form type Response.
Sub Queryclose(Source As Notesuidocument, Continue As Variant) '// Send a bookmark to the sales manager for this project. '// This is located on the Project document (main topic, or top most document in this discussion thread). Dim session As New NotesSession Dim db As NotesDatabase Set db = session.CurrentDatabase Dim doc As NotesDocument Set doc = Source.Document ' Find the main topic document. Dim MainTopic As NotesDocument Get MainTopic = GetParentDocument( doc ) 'here we are calling our "GetParentDocument" function If MainTopic Is Nothing Then Exit Sub 'if the document can't be found, we have nothing to do ' Create the bookmark document Set bookmark = New NotesDocument( db ) 'create a new document to be mailed to the sales manager 'add a doclink to the bookmark Set rtitem = New NotesRichTextItem( bookmark, "Body" ) 'create a new rich text Body field on the document Call rtitem.AppendDocLink( doc, InheritedDbTitle ) 'place a doclink in the Body field 'add content to the bookmark bookmark.Form = "Bookmark" bookmark.Subject = doc.Subject(0) bookmark.InheritedDBTitle = db.Title bookmark.InheritedSubject = doc.Subject(0) bookmark.FlowStatus = "Please review the following document" bookmark.~_ViewIcon = 11 'view icons appear in the Inbox, 1-175 bookmark.CopyTo = "" bookmark.BlindCopyTo = session.Username 'blind carbon copy the current user 'address the document to the sales manager bookmark.SendTo = MainTopic.SalesManager(0) 'place the SalesManager (located on the MainTopic) in the SendTo field 'send the bookmark If Not( bookmark.SendTo(0) = "" ) Then Call bookmark.Send( False ) End If End Sub