Domino Code Fragment

Code Name*
Retriving Parent and Child Documenst from a View
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.142.200.226
Description*
This example demonstrates how to retreive a parent document from a view, and then proceed to retreive information from all of the Parent's child documents.
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
This example demonstrates how to retreive a parent document from a view, and then proceed to retreive information from all of the Parent's child documents. Once all the child documents have been accessed, the next parent and it's child documents are processed. Notice the method view.GetChild is used to set an object to a child document of a parent. If the object is set to "", the end of the child set has been reached, and the script can move to the next parent.

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 grandchild As NotesDocument
'Declare grandchild as a Notes Document
Dim ParentText As Variant
'Declare ParentText as type variant
Dim ChildText As Variant
'Declare ChildText as type variant
Dim GrandChildText As Variant
'Declare GrandChildText as type variant
Set db = session.CurrentDatabase
'Set db to the current database (open)
Set view = db.GetView("Examples")
'Set view to a view called "Examples"
Set doc = view.GetFirstDocument()
'Set doc to the first document in "Examples"
While Not(doc Is Nothing)
'Loop while there are still documents to process
ParentText = doc.Subject
'Set variable ParentText to the value in field Subject
Messagebox ParentText(0) + " **This comes from a parent document.**"

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

'Display the Subject field from the current child document
Set grandchild = view.GetChild(child)
'Set grandchild to the first child-child document
While Not(grandchild Is Nothing)
'loop while where are still grandchild document of the current child document
GrandChildText = grandchild.Subject
'set variable GrandChildText to the value of the field Subject
Messagebox GrandChildText(0) + "**This comes from a response to response document.**"

'Display the Subject field from the current grandchild document
Set grandchild = view.GetNextSibling(grandchild)
'Set grandchild to the next grandchild document
Wend
Set child = view.GetNextSibling(child)
'Set child to the next child document
Wend
Set doc = view.GetNextDocument(doc)
'Set doc to the next parent document
Wend