Updating Response documents when parent data changes

Updating Response documents when parent data changes

Occassionally I develop applications that require response documents to maintain certain data contained within the parent document. When certain data in the parent document changes, all response documents also need to change.

The following code/script helps accomplish that task. The parent document maintains a list of field names that are inherited by the response document. When the parent document is saved, that list is used to determine which fields have changed. If any data has changed, the immediate responses are updated with the new data. NOTE: This code only updates immediate reponses. It could be modified to handle responses to responses.


  1. Create a hidden field called "InheritedFields" on the parent form that is multivalue text. The value should be a list of all field names that need to be updated on child document when updates are made to parent(e.g. "Field1" : "Field2" : "Field3").
  2. In the Declarations of the parent form, include the following:
    'handle to parent document
    Dim doc As NotesDocument
    
    'two dimensional array containing field name and field value
    Dim inheritFieldsArray As Variant
    
  3. In the QueryModeChange of the parent form:
    Dim listOfInheritedFields As Variant
    Dim doc As NotesDocument
    'when document enters edit mode, capture original values to compare during save If Not(source.IsNewDoc) And Not(source.EditMode) Then Set doc = Source.Document listOfInheritedFields = doc.InheritedFields

    Requires Free Membership to View

    Register today to access targeted resources from our editorial writers and independent industry experts focused on Lotus Domino, Notes, Workplace and other related technologies.

    By submitting your registration information to SearchDomino.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchDomino.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

  1. Redim inheritFieldsArray(0 To Ubound(listOfInheritedFields), 0 To 1) For i=0 To Ubound(listOfInheritedFields) inheritFieldsArray(i, 0) = listOfInheritedFields(i) inheritFieldsArray(i, 1) = Source.FieldGetText(listOfInheritedFields(i)) Next End If
  2. Create UpdateChildDocuments sub routine:
    Sub UpdateChildDocuments
     Dim actDC As NotesDocumentCollection
     Dim actDoc As NotesDocument
     Stop
     Set actDC = doc.Responses
     If actDC.Count > 0 Then
      Dim fieldUpdateArray() As String
      Dim fieldUpdateCount As Integer
      fieldUpdateCount = 0
      
              'initialize array to ""
      Redim fieldUpdateArray(0 To 0)
      fieldUpdateArray(0) = ""
      
              'there are activities for this document--continue checking to see if updates are necessary
      For i=0 To Ubound(inheritFieldsArray)
       fieldName = inheritFieldsArray(i,0)
       origFieldVal = inheritFieldsArray(i,1)
       currFieldVal = doc.GetItemValue(fieldName)(0)
       If (origFieldVal <> currFieldVal) Then
                        'the value has changed--flag for update
        Redim Preserve fieldUpdateArray(0 To fieldUpdateCount)
        fieldUpdateArray(fieldUpdateCount) = fieldName
        fieldUpdateCount = fieldUpdateCount + 1
       End If
      Next
      
      If fieldUpdateArray(0) <> "" Then
                   'updates need to be performed
       Set actDoc = actDC.GetFirstDocument
       While Not (actDoc Is Nothing)
                        'for each activity document, replace the changed values
        For i=0 To Ubound(fieldUpdateArray)
         currVal = doc.GetItemValue(fieldUpdateArray(i))(0)
         Call actDoc.ReplaceItemValue(fieldUpdateArray(i), currVal)
        Next
        Call actDoc.Save(True, True)
        Set actDoc = actDC.GetNextDocument(actDoc)
       Wend
      End If
     End If
     
    End Sub
    
  3. In the QuerySave of parent document:
    Set doc = Source.Document
    'update any child documents if values have changed
    If Not (Source.IsNewDoc) Then
     UpdateChildDocuments
    End If
    

This was first published in September 2002

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.