This tip shows how to create a LotusScript function that returns the top-level document in a response thread.


Brian Green, Presented by Lotus Software, IBM Corporation

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.

01 October 1998

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 )
          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


developerWorks: Sign in

Required fields are indicated with an asterisk (*).

Need an IBM ID?
Forgot your IBM ID?

Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.


All information submitted is secure.

Dig deeper into IBM collaboration and social software on developerWorks

ArticleTitle=Finding the Top-level Document