Practically, using the Notes client software, a response document is created from a special form, which automatically links the new document to the one which is selected in the currently open view. Technically, a response document is a document that contains a reference to another document in a field named '$REF'. The reference is established using the parent documents note ID, which uniquely identifies the parent note.
To establish a parent-child or parent-response relationship between documents, you need to have two documents from the same database. There is only a one way assignment: from child to parent.
Here is a step-by-step example how to establish a parent-child relationship between two documents:
| parentNote childNote connection database | "Startup runtime system" AbtLnEnvironment startUp. "Create a connection t local databases" connection := AbtLnConnection local. "Open one of the sample databases provided with the feature" database := connection openDatabase: 'VASAMPLE\VASAMPLE.NSF'. "Create a new document and associate it with the 'Main Topic' form. Execute default value formulas" parentNote := database newNoteFromComputedForm: 'Main Topic'. "Set the Subject field to 'ParentNote'." parentNote at: 'Subject' put: 'ParentNote'. "Store the document. Execute input translation and input validation formulas" parentNote store. "Create a new document and associate it with the'Response' form. Execute default value formulas" childNote := database newNoteFromComputedForm: 'Response'. "Set the Subject field to 'Response'." childNote at: 'Subject' put: 'Response'. "Establish the parent/child relationship" childNote becomeResponseNoteTo: parentNote. "Store the document" childNote store. "Close the database" database close. "Shutdown runtime system" AbtLnEnvironment shutDown.
There are two ways to identify child documents to a parent. You can either use a view that displays the response hierarchy and iterate using the children protocol with the tree nodes. Or you can use the responseNotes protocol with an AbtLnNote instance.
Here is a step-by-step example how to retrieve the number response documents of each Main Topic document in a discussion database.
| allParents connection database | "Startup runtime system" AbtLnEnvironment startUp. "Create a connection t local databases" connection := AbtLnConnection local. "Open one of the sample databases provided with the feature" database := connection openDatabase: 'VASAMPLE\VASAMPLE.NSF'. "Read all the main topic documents" allParents := database allNotesFromQuery: 'Form="MainTopic"'. "Print the subject of each document that has responses and print the number of responses to each document" allParents do: [ :e | | responses | ( responses := e responseNotes) isEmpty ifFalse: [ Transcript nextPutAll: ('The document : ', (e fill at: 'Subject')); nextPutAll: (' has ', responses size printString, ' response documents'); cr. ] ]. "Close the database" database close. "Shutdown runtime system" AbtLnEnvironment shutDown. AbtLnEnvironment
You can certainly access each individual response document that is returned from the responseNotes message.