I create a Master document and click a button which then creates 5 Response documents and populates specific fields.
All is working OK
Users then enter a complete date on a response doument.
Here is my question: When all 5 response documents have completed dates I want to then create an email
I’m not sure how and what needs to be created to do this… also I have an alternative problem. The user can create additional responses under the same parent so how do I determine then the total responses to then send this email.?
In summary I need to send an email when all responses for a single Parent( master) have completed dates.
how about something like this in the Response form:
Sub Postsave(Source As Notesuidocument)
Dim session As New NotesSession
Dim dbCurrent As NotesDatabase
Dim docParent As NotesDocument
Dim colChildren As NotesDocumentCollection
Dim docChild As NotesDocument
Dim bAllComplete As Boolean
Dim docEmail As NotesDocument
bAllComplete = True
Set dbCurrent = session.CurrentDatabase
Set docParent = Nothing
On Error Resume Next 'GetDocumentByUNID errors if no doc found
Set docParent = dbCurrent.GetDocumentByUNID(Source.Document.ParentDocumentUNID)
If Not docParent Is Nothing Then
Set colChildren = docParent.Responses
Set docChild = colChildren.GetFirstDocument
While Not docChild Is Nothing
If Cstr(docChild.GetItemValue("CompleteDate")(0)) = "" Then
bAllComplete = False
End If
Set docChild = colChildren.GetNextDocument(docChild)
Wend
If bAllComplete Then
'add email sending code here
Set docEmail = dbCurrent.CreateDocument
Call docEmail.ReplaceItemValue("Form", "Memo")
Call docEmail.ReplaceItemValue("Subject", "All Done!")
Call docEmail.ReplaceItemValue("SendTo", "Whoever")
Call docEmail.Send(False)
End If
End If
When I need to control the number of children or gather all the children for a parent, I create a hidden view for the response form only where the first column is categorized by @Text($Ref). Then somewhere on the parent - or in the children when necessary - I gather the number of entries from the view. If you can use formula, @Dblookup will work. If you need script, use GetAllDocumentsbyKey.