Subject: RE: Decending by # of doc children?
Ben is suggesting that you write a scheduled agent in LotusScript to do something along the following lines (not tested!!!):
Sub Initialize
Dim ses as New NotesSession
Dim db as NotesDatabase
Dim dc as NotesDocumentCollection
Dim dcResp as NotesDocumentCollection
Dim doc as NotesDocument
Dim docResp as NotesDocument
Set db = ses.CUrrentDatabase
Set dc = db.UnprocessedDocuments
If dc.COunt > 0 Then
Set doc = dc.GetFirstDocument
Do WHile Not doc Is Nothing
doc.ReplaceItemValue “ChildDocumentCount”, 0
Set dcResp = doc.Responses
If dcResp.Count > 0 Then
Set docResp = dcResp.GetFirstDocument
Do WHile Not docResp Is Nothing
If docResp.HasItem(“$Conflict”) Then 'Not really a true response
Else
doc.ReplaceItemValue “ChildDocumentCount”, doc.ChildDocumentCount(0) + 1
End If
Set docResp = dcResp.GetNextDocument(docResp)
End If
doc.Save True, False 'Save the changes even if response count is zero
Set doc = dc.GetNextDocument(doc)
Loop
End If
End Sub
After the agent runs, each parent document will contain a field called ChildDocumentCount that can be used as a sortable field in the view.
THe agent will need to have modifications if you want to filter “parent” documents based on some kind of form or other value and that can be done either in the agent or as a criteria in the agent’s search parameter. You might also want to consider whether you want to count only direct descendants or any grandchild documents, etc. too (in which case, use recursion). Also, the agent could have some more smarts to not update the document if the response count is the same as is already in the document, but you get the general idea, right?