Domino Code Fragment

Code Name*
Function GetParentDocument( doc As NotesDocument )
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.145.105.108
Description*
This is a recursive function. It returns the main document at the top of a thread. An example of a thread is a main topic with multiple response documents. Passing the NotesDocument object reference variable to this function would return the main topic at the top of the thread. Call this function using GetParentDocument(doc).
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
ABOUT THE AUTHOR
Brian Green is a software engineer for Automated Logic Corporation. ALC is a manufacturer of hardware and software used for Building Automation Systems. Their products are used for monitoring and controlling various building functions such as heating, air conditioning, lighting, and so on. Brian has been using Notes since 1996. He is currently working on internal thin client applications using Domino and Java.
Files/Graphics attachments (if applicable): Code:
Function GetParentDocument( doc As NotesDocument ) As NotesDocument
'This is a recursive function. It returns the main document at the top of a thread.
'An example of a thread is a main topic with multiple response documents.
'Passing the NotesDocument object reference variable to this function would return the main topic at the top of the thread.
'Call this function using GetParentDocument(doc).


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