Monday, September 26, 2011

Update a field in response documents after it is changed in the parent document

Assumptions:

1) The name (or synonym) of the Response form is "TASK" and it inherits field values.
2) The name of the field to synchronize is "STATUS" in both Project and Task forms. This    is computed when composed to inherit from the parent form. Include the following Script code in the QuerySave event of the parent form:

Sub Querysave(Source As Notesuidocument, Continue As Variant)
  Dim Collection As NotesDocumentCollection
  Dim Doc As NotesDocument
  Dim Form, ParentStatus, Status As String
    
  Set Doc = Source.Document
  Set Collection = Doc.Responses
  Set Doc = Collection.GetFirstDocument
  ParentStatus = Source.FieldGetText("STATUS")
  While Not ( Doc Is Nothing )
    Form = Doc.GetItemValue("Form")(0)
    Status = Doc.GetItemValue("Status")(0)
    If (Form = "TASK")And (Status <> ParentStatus) Then
      Call Doc.ReplaceItemValue( "STATUS", ParentStatus )
      Call Doc.Save (True, False)
    End If
    Set Doc = Collection.GetNextDocument(Doc)
  Wend
End Sub

No comments:

Post a Comment