Domino Code Fragment

Code Name*
Find the Parent Document to a Child Document
Date*
05/14/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.52.14.110.28
Description*
In the script below, the child document is found using GetFirstDocument and GetNextDocument . You might ask yourself `Why not use GetNthDocument instead?'. The reason is GetNthDocument only works in documents in a collection, and we are working in a view!
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
Sometimes in your script you may be pointing to a response document and need to find out what documet is the parent of that child document. The NotesView class provides a method named GetParentDocument to do just that. GetParentDocument can return a document, a response document, or a response to response document, depending on what kind of document is used as a parameter to the method. If a view has been filtered by using FTSearch, GetParentDocument does not return the true parent of a document; it simply returns the previous document in the view.


Click here to view the example.

Dim session As New NotesSession 'Declare session as a new Notes session
Dim db As NotesDatabase
'Declare db as a Notes Database
Dim view As NotesView
'Declare view as a Notes View
Dim doc As NotesDocument
'Declare doc as a Notes Document
Dim child As NotesDocument
'Declare child as a Notes Document
Dim Temp As Variant
'Declare Temp as variant
Dim Temp2 As Variant
'Declare Temp2 as variant
Set db = session.CurrentDatabase
'Set db to the current Notes database (open)
Set view = db.GetView("Examples")
'Set view to a view called "Examples"
Set child = view.GetFirstDocument
'set child to the first document in the view
Set child = view.GetNextDocument(child)
'set child to the Next document (the child)
Temp = child.Subject
'Temp is set to the child field Subject
Messagebox Temp(0) + " is the response document."
'Display that Temp is a Reponse
Set doc = view.GetParentDocument(child)
'set doc to the parent document of the current child
Temp2 = doc.Subject
'Temp2 is set to the parent document field Subject
Messagebox Temp2(0) + " is the parent document to " + Temp(0)

'Display the child and parent subjects