前提条件
- ビューに「返答への返答文書」がない。
- ビューに返答専用の列が 1 つ含まれており、返答に関する情報 (Subject など) が表示されている。
Sub Initialize
Dim db As New NotesDatabase( "", "corn.nsf" )
Dim view As NotesView
Dim responsePos As Integer
Dim doc As NotesDocument
Dim rtitem As Variant
Dim response As NotesDocument
Dim tempResponse As NotesDocument
Set view = db.GetView( "All" )
' find the position of the Responses-only column
Forall c In view.Columns
If c.IsResponse Then
responsePos = c.Position
End If
End Forall
Set doc = view.GetFirstDocument
' visit each main document in the view
While Not( doc Is Nothing )
Set rtitem = doc.GetFirstItem( "Body" )
Set response = view.GetChild( doc )
' visit each response to the main document
While Not( response Is Nothing )
' fold the response's column value into the parent
Call rtitem.AppendText _
( response.ColumnValues( responsePos - 1 ) )
Call rtitem.AddNewLine( 1 )
' save a temporary copy of current response...
Set tempResponse = response
' ...so that the script can get the next response...
Set response = view.GetNextSibling( response )
'...and then delete the current response.
Call tempResponse.Remove( True )
Call view.Refresh
Wend
Call doc.Save( True, True )
Set doc = view.GetNextSibling( doc )
Wend
End Sub
たとえば、[All] ビューが主要文書 1 つと返答文書 3 つを含む場合を考えます。各返答文書の件名と作成者が、返答専用の列に次のように表示されているものとします。
好きな色は?(Shelley Kinnamon)
青 (Joe Doyle)
紫 (Peg Yip)
オレンジ (Kendra Zowker)
このスクリプトでは 3 つの返答文書を削除して、データベースに主要文書だけが残るようにします。
好きな色は?(Shelley Kinnamon)
主要文書の [Body] フィールドには次の文字列が含まれます。
青 (Joe Doyle)
紫 (Peg Yip)
オレンジ (Kendra Zowker)