Manage Learn to apply best practices and optimize your operations.

Updating Response documents when parent data changes

This tip describes 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 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
  4. 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
    
  5. 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 last published in September 2002

Dig Deeper on Lotus Notes Domino Administration Tools

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchExchange

SearchContentManagement

Close