Refreshing inherited fields in a response doc

I have a response document that inherits some field values from a main form and was wondering if there was any way to have those fields automatically refresh in the response doc when the main document is updated. Any help would be greatly appreciated!

Subject: Refreshing inherited fields in a response doc

Typically, you would evaluate the parent document when it is saved to determine if anything has been changed. If so, then you can use script to make those same changes to the response documents.

For instance, in the form design of the parent document (in the “Globals” section), you would define a container variable…

Dim originalStatus$

Then, in the “PostOpen” event of the form, you could use the following statement to save the original value of the field…

originalStatus$ = Source.FieldGetText( “Status” )

Finally, in the “QuerySave” form event, you could use the following statements to refresh the response documents…

Set thisDoc = Source.Document

If thisDoc.Status(0) <> originalStatus$ and Not( thisDoc.IsNewNote ) Then

Call UpdateResponses( thisDoc )

originalStatus$ = thisDoc.Status(0)

End If

The “UpdateResponses” function would be recursive (it would call itself) so as to consider a multi-level response hierarchy…

Dim responses As NotesDocumentCollection

Dim respDoc As NotesDocument

’ Collect the responses

Set responses = doc.Responses

If responses.Count > 0 Then

’ Update the immediate responses with the new status value

Call responses.StampAll( “Status”, doc.Status(0) )

’ Now, recursively search for more responses (to responses)

Set respDoc = responses.GetFirstDocument

Do While Not( respDoc Is Nothing )

  Call UpdateResponses( respDoc )

  Set respDoc = responses.GetNextDocument( respDoc )

Loop

End If

I think this should work for you.

I coded it “off the cuff” tho, so you’ll wanna test the syntax/logic.

Hope it helps!

T.

Subject: RE: Refreshing inherited fields in a response doc

Thanks for the responses. This should be only a 1x thing, I am adding a field to the parent doc and wanted its value to be updated into a new field in the response docs, so I will try Stan’s suggestion. Thanks!

Subject: Refreshing inherited fields in a response doc

No. At least not using inheritance alone, that is, since inheritance only happens at themoment of composition. You can use computed fields with this general formula:

@If(@IsNewDoc; Fieldname; @GetDocField(@Text($Ref);“Fieldname”))

However, that will mean that the documents need to be opened and refreshed or refreshed using ComputeWithForm or @Command([ToolsRefreshAllDocs]). If you want it to happen more or less automatically, you’ll need to use some code on the parent document form to get the Responses collection and update the documents that way. If the main docs are being changed programmatically, you will need to ensure that the responses are also updated with the same agent/action.

Subject: RE: Refreshing inherited fields in a response doc

Nobody mentioned the other option, which is to avoid storing copies of the data – use a Computed for Display field and look up the data from the parent document.