The script calculates an item value in a main document based on
item values in its response documents. Here, the total item in a main
document is calculated to be the sum of all the total items of its
responses. The script moves from one main document to the next and
from one response document to the next. The Main View is not categorized.Dim db As New NotesDatabase( "Cape-Town", "richardj.nsf" )
Dim view As NotesView
Dim parentDoc As NotesDocument
Dim responseDoc As NotesDocument
Set view = db.GetView( "Main View" )
Set parentDoc = view.GetFirstDocument
' Visit each main document in the view
While Not ( parentDoc Is Nothing )
newTotal% = 0
Set responseDoc = view.GetChild( parentDoc )
' Visit each of the parent's response documents
While Not ( responseDoc Is Nothing )
subtotal = responseDoc.GetItemValue( "total" )
newTotal% = newTotal% + Cint( subtotal( 0 ) )
Set responseDoc = view.GetNextSibling( responseDoc )
Wend
' Put the new total onto the parent document
Call parentDoc.ReplaceItemValue( "total", newTotal% )
Call parentDoc.Save( True, False )
Set parentDoc = view.GetNextSibling( parentDoc )
Wend