Domino Code Fragment

Code Name*
Retriving Parent Documents with Child and Grandchild Documents
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.13.58.247.31
Description*
This example demonstrates how to retrieve information from a parent document in a view, and all of the Parent's child and grandchild documents.
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
This example demonstrates how to retrieve information from a parent document in a view, and all of the Parent's child and grandchild documents. Once all the child and grandchild documents have been accessed for a parent document , the next parent and it's associated documents are processed. Notice the NotesView method GetChild is used to set an object to the first child document of a parent. GetNextSibling is then used to find any other child documents. If the object is set to "", the end of the child set has been reached, and the script can retrieve any grandchild documents available. To retrieve the first grandchild document, GetChild is used with child as a parameter. If a grandchild document is found, GetNextSibling is used with grandchild as a parameter to retrieve all the grandchild documents. This is done until grandchild is set to "", at which time GetNextSibling with a parameter of doc is used to find the next parent 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 type
Dim child As NotesDocument
'Declare child as a Notes Document type
Dim grandchild As NotesDocument
'Declare gandchild as a Notes Document type
Dim ParentText As Variant
'Declare ParentText as variant type
Dim ChildText As Variant
'Declare ChildText as variant type
Dim GrandChildText As Variant
'Declare GrandChildText as variant type
Set db = session.CurrentDatabase
'Set db to the current Notes database (open)
Set view = db.GetView("Examples")
'Set view to the Notes view Examples
Set doc = view.GetFirstDocument()
'Set doc to the first document in the view
While Not(doc Is Nothing)
'Loop while there are still documents to process
ParentText = doc.Subject
'Set ParentText to the Subject field in doc
Messagebox ParentText(0) + " **This comes from a parent document.**"

'Display the subject of the current document
Set child = view.GetChild(doc)
'Set child to the first child of doc
While Not(Child Is Nothing)
'Loop while there are still child docs to the current doc
ChildText = child.Subject
'set ChildText to the Subject of the current child
Messagebox ChildText(0) + "**This comes from a response document.**"

'Display the subject of the current child
Set grandchild = view.GetChild(child)
'set grandchild to the first grandchild of the current child
While Not(grandchild Is Nothing)
'Loop while there are still grandchild docs to the current child
GrandChildText = grandchild.Subject
'set GrandChildText to the Subject of the current grandchild
Messagebox GrandChildText(0) + "**This comes from a response to response document.**"

'Display the subject of the current grandchild
Set grandchild = view.GetNextSibling(grandchild)
'Set grandchild to the next grandchild document in the view
Wend
Set child = view.GetNextSibling(child)
'Set child to the next child document in the view
Wend
Set doc = view.GetNextSibling(doc)
'Set doc to the next parent document in the view
Wend