Hello,
I am calling this sub routine from a script to send an email. But I have a question with Dynamic array.
Following is the code which works fine but I want to implement dynamic array in it.
Sub SendMail ( req As NotesDocument )
Dim who As Variant
Dim email As NotesDocument
Dim docCreator As String
Set email = New NotesDocument( db )
who = req.Field1 ' This field is a multivalue field.
' Comment - I want to pull the values from this field, and send an email to each person.
' Problem - But I don't know how to define dynamic array and pull the value from an array
Dim recipientsSto
Dim recipientsCc ( 1 To 5 ) As String
recipientsCc( 1 ) = "User1"
recipientsCc( 2 ) = "User2"
recipientsCc( 3 ) = "User3"
recipientsCc( 4 ) = "User4"
email.Form = "Memo"
email.SendTo = who ' This sends an email to only first value
email.CopyTo = recipientsCc ' Cc: goes to multiple user as defined in a Fixed array above.
email.Subject = "Test message"
email.SaveMessageOnSend = False
email.Send( False )
Call req.Save( False, True )
End Sub
Any idea how to define a dynamic array and pull the value out of dynamic array and send an email to each user out of that dynamic array?
Thanks
MS
Subject: Dynamic array
Hi Manish,
Use Lbound and or Ubound to set\get the limits of the array. Loop through the array.
Example:
Dim s As New NotesSession
Dim db As New NotesDatabase(“”,“”)
Dim doc As NotesDocument
Dim dc As NotesDocumentCollection
Dim sales()
If db.Open(“server/US”,“filename.nsf”) Then
Set dc = db.AllDocuments
For x = 1 to dc.Count
Set doc = dc.GetNthDocument(X)
If doc.salesID(0) = "1234" Then
If (x=1) Then
Redim sales(0)
sales(0) = doc.salesAmount(0)
Else
Redim Preserve sales(Ubound(sales) + 1)
sales(Ubound(sales)) = doc.salesAmount(0)
End If
End If
Next
MessageBox “There were " & Ubound(sales) & " documents found for 1234”,0,“Count”
Dim total
total = 0
Forall y In sales
Msgbox "Sales amount #" & x & " is $" & y
total = total + y
End Forall
MsgBox "Total sales: " & total
End If
Subject: RE: Dynamic array
Thanks Bafie for your reply.
This code is more specific to multiple documents in a database.
But how to generate dynamic array based upon multiple values in a field within the document?
MS
Subject: Dynamic array
Manish,
If I understand your question correctly, you have a multi-value text list field. You don’t need to move it to script, just use the field directly - it is already an array:
email.SendTo = req.Field1
To get into script:
Dim recipientsTo as Variant
recipientsTo = req.Field1
–Ron
Subject: Dynamic array
From your field req.field1
Use forall:
ForAll tmpName in req.Field1
email.SendTo = tmpName
email.CopyTo = recipientsCc
…
End ForAll
hope this helps
Regards
Joe