Lotusscript Send Method only emails first recipient in multiple value text field

code is called from form button, where a dialog box presents an email comments form that the user can check or uncheck computed names (ToField) to email discussion text to.  The names are @Exploded from 3 other fields and presented to the use in a checkbox format, where the results of the user selection are saved to the ToField and utilized in the send method to address discussion email.

If the user selects more than one name the email only goes to the first name, what am I doing wrong?
Sub Initialize
	Dim session As New notessession
	Dim ws As New notesuiworkspace
	Dim newdoc As NotesUIDocument, uidoc As NotesUIDocument
	Dim doc As notesdocument,  IDdoc As notesdocument, maildoc As NotesDocument
	Dim db As notesdatabase
	Dim rtitem As NotesRichTextItem	
	Dim uidocflag As Integer
	Dim OldNotes As String, NewNotes As String
	Dim tempInput As String, Username As String, tempNameText  As String
	Dim EditorName As New NotesName(session.UserName)
	Dim nam As NotesName
	On Error Goto ErrorHandler
	Dim richStyle As NotesRichTextStyle
	Dim vSendTo As Variant
	
	Set db = session.CurrentDatabase	
	
	Username = EditorName.Common
	EmailName = EditorName.Abbreviated
	
	tempInput = ">" + Username + " - " + Now
	
	Set richStyle = session.CreateRichTextStyle
	
	Set newdoc = ws.CurrentDocument    'Current UI document
	Set doc = newdoc.document ' Current Backend Document	
	doc.tempComment = ""
	OldNotes = doc.Discussion(0)
	
	Set maildoc = db.CreateDocument
	maildoc.Form = "Memo"	
	
	Set rtitem = New NotesRichTextItem( maildoc, "Body" )          
	
	uidocflag = ws.DialogBox( "EmailComment", True, True, False, False, False, False, "Discussion Text.", doc)   'dialog box pop up  
	If uidocflag = -1 Then    'if True set variables  
		NewNotes = doc.tempComment(0)
		doc.tempComment = ""
		doc.Discussion = tempInput + Chr(10) + NewNotes + Chr(10) + Chr(10) + OldNotes
		
		richStyle.Bold = True
		Call rtitem.AppendStyle(richStyle)	
		Call rtitem.AppendText("New Discussion Text:")
		richStyle.Bold = False
		Call rtitem.AppendStyle(richStyle)
		Call rtitem.AddNewLine(2)
		Call rtitem.AppendText(NewNotes)
		Call rtitem.AddNewLine(2)
		Call rtitem.AppendDocLink( doc, "Document location - US-IFSAPP003\" & db.FilePath)
		Call rtitem.AppendText(" <--- Doc link (Discussion text can be found at bottom of form.)")
		Call rtitem.AddNewLine(2)	
		
		richStyle.Bold = True
		Call rtitem.AppendStyle(richStyle)	
		Call rtitem.AppendText("Discussion History: ")
		richStyle.Bold = False
		Call rtitem.AppendStyle(richStyle)
		Call rtitem.AddNewLine(2)
		Call rtitem.AppendText(doc.Discussion(0))	
		Call rtitem.AddNewLine(2)
		
		maildoc.Subject = "CRE Credit Form Discussion: " + doc.ClientName(0) +" - "+ doc.FeeText(0) +" - "+ doc.BDMName(0)
		
		vSendTo= doc.ToField(0)
		
		If vSendTo = "" Then
			Msgbox("No Recipient Selcted. Process Cancelled.")
			Exit Sub
		End If
		maildoc.SendTo = vSendTo   'for live use
		
		If Isarray(vSendTo) Then
			Dim tempSize As Integer
			tempSize = Ubound(vSendTo) + 1
			
			For i = 1 To tempSize
				Set nam = session.CreateName(vSendTo(i-1))
				tempNameText = tempNameText  + nam.Common + " - "
			Next
			
			doc.Discussion = tempInput + Chr(10) + NewNotes + Chr(10) + Chr(10) + OldNotes ' update Discussion field
		Else
			doc.Discussion = tempInput + Chr(10) + NewNotes + Chr(10) + Chr(10) + OldNotes ' update Discussion field			
		End If
		
		Msgbox "Mail Send To " & Implode(mailDoc.GetItemValue("SendTo"),";") 'view send to
		
		Call maildoc.Send(False)
		Call doc.Save(True, False)  	
		Call newdoc.Close
	End If
	Exit Sub
	
ErrorHandler:	
	Msgbox("ERROR: " & Err() & " : " & Error() & "." & "Occured on line " & Erl() & "  Error Key = " )     'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX       rim out after testing
	If Err() = 4295 Then
		If ReleaseCheckConfirm = "YES" Then
			ReleaseChangeDoc.MailFailureFlag = "Yes"
			Call ReleaseChangeDoc.Save(False, False) 
			Resume Next
		Else
			maildoc.MailFailureFlag = "Yes"
			Call maildoc.Save(False, False) 
			Resume Next
		End If
		maildoc.MailFailureFlag = "Yes"
		Call maildoc.Save(False, False) 
		Resume Next
	Elseif Err() = 4294 Then
		Msgbox("ERROR: One or more of the intended receipts email addresses are invalid. Check them, correct and re-save.")
		Exit Sub	
	Elseif Err() = 4000 Then
		If Instr(1, Error(), "already locked") > 0 Then
			Msgbox("ERROR: This process updates associated CT documents and " & BlockedCT & " is being held by : " & BlockedCTName & ". Contact this person or the database manager to have it unlocked.") 
			'Resume Next
			Exit Sub	
		Else
			Msgbox("ERROR: No Sender address on email. Contact the database manager for assistance.") 
			
			Exit Sub
		End If		
	Else
		Exit Sub
	End If
	
End Sub

Open in new window

CRE-Discussion-Dialogbox.bmp
lahlf001Asked:
Who is Participating?
 
Sjef BosmanConnect With a Mentor Groupware ConsultantCommented:
That is not going to do what you want. Some explanation:

            vSendTo= doc.ToField(0)  ' you pick ONLY the first value of a field in the document...
            ...
            ...            
            If Isarray(vSendTo) Then ' it is therefore NEVER an array, the condition is always False

You could try with

            vSendTo= doc.ToField  ' now it's always an array, by definition
           
            If vSendTo(0) = "" Then
                  Msgbox("No Recipient Selected. Process Cancelled.")
                  Exit Sub
            End If
            maildoc.SendTo = vSendTo   'for live use
           
            If Isarray(vSendTo) Then
0
 
lahlf001Author Commented:
Thank you!  
This response not only help me with my immediate project, but you helped me grow by explaining why what I was doing would not work.

After making you suggested modification, I was able to get teh email result that I wanted.

Thanks for the quick response!
0
 
Sjef BosmanGroupware ConsultantCommented:
Wonderful!
0
All Courses

From novice to tech pro — start learning today.