CopyTo multivalue list not showing in LotusScript email

I have a email that is created when the customer service rep enters a call and then clicks a button "Submit Request to Team". They enter the team name in the S_Team field and then can enter more then one value in the Copy to field CopyTo. I have been having the issue that when they put more then one name in the copy to field that it will only send to the first person listed. I have found the answer that a dynamic array needs to be defined for the copyto field but I have no idea how to write it. I have tried for the past two days to figure this out and I keep failing.

What I thought I would need to add is to delcare "copylist" as a variant, then set copylist to the doc.CopyTo and then call the copylist in the mailsend function. That is not working. I am lost. Arrays are not my strength and I need some help.

Sub Click(Source As Button)
	Dim s As NotesSession
	Dim db As NotesDatabase
	Dim ws As NotesUIWorkspace
	Dim uidoc As NotesUIDocument
	Dim doc As NotesDocument
	Dim edoc As NotesDocument
	Dim rtitem As NotesRichTextItem
	Dim user As String
	Set s = New NotesSession
	Set db = s.CurrentDatabase
	Set ws = New NotesUIWorkspace
	Set uidoc = ws.CurrentDocument
	Set edoc = New NotesDocument(db)
	Set doc = uidoc.Document
	Set rtitem = New NotesRichTextItem(edoc, "Body")
	doc.AllowClose = "1"
	doc.SaveOptions = "1"
	doc.Status = "Pending"
	doc.Person =doc.SubmittedBy
	doc.Action= "Submitted Request"
	doc.ActionDate = Now
	doc.Status_Final="Closed - Forwarded"
	Set item = doc.GetFirstItem( "Person" )
	Call item.AppendToTextList( doc.SubmittedBy )
	Set item = doc.GetFirstItem( "Action" )
	Call item.AppendToTextList( "Forwarded" )
	Set item = doc.GetFirstItem( "ActionDate" )
	Call item.AppendToTextList (Date$ + " " + Time$)
	Dim T As String
	T=Inputbox("Please enter any email comments.")
	Call uidoc.Refresh
	edoc.SendTo = doc.Email_Address(0)
	edoc.CopyTo = doc.CopyTo(0)
	edoc.Subject = "Please review following Phone Request " + doc.Policy(0)
	Call rtitem.AppendText("Please Review")
	Call rtitem.AddNewline(2)
	Call rtitem.AppendText("Email Comments: "+T)
	Call rtitem.AddNewline(2)
	Call rtitem.AppendText("Link to Document ==> ")
	Call rtitem.AppendDocLink(doc, "", "")
	Call edoc.Send(False)
	Messagebox "Your phone call has been sent to "+doc.S_Team(0), 64, "Sent"
	Call uidoc.Save
	Dim workspace As New NotesUIWorkspace
	Dim parent As notesUiDocument
	Set parent = ws.currentDocument
	Call workspace.ComposeDocument( "", "", "Call" )
End Sub

Open in new window

Who is Participating?
Bill-HansonConnect With a Mentor Commented:
You are correct, the code above will work.

In a nutshell, use dynamic arrays when you don't know how many items will be in the array until runtime (like when you collect data from a document collection, or when updating document items).

I use fixed arrays for only a few circumstances, like when I'm doing a view lookup.  They are handy for setting the key values, and you always know how many keys will be needed.

Regarding redim...  It stands for redimension, and it allows you to change the number of elements that a dynamic array can hold.  Ubound tells you how many items an array can currently hold.  So, you can use the two together to increase the size of a dynamic array at run time.

For example, if you are iterating over a document collection, and you want to collect all of the values for a given field, you can do that like this...

dim array as Variant
Set doc = dc.GetFirstDocument
Do While (Not doc Is Nothing)
      redim preserve array(ubound(array)+1)
      array(ubound(array)) = doc.Name(0)
      Set doc = dc.GetNextDocument(doc)

Notice that I used the Preserve keyword.  If you leave this out, redim will erase any values already stored in the array.  Including Preserve tells redim to keep all values already stored.

On another note, I never use AppendToTextList (I noticed you use it in your code).  Sometimes, AppendToTextList creates duplicate item names, which I don't like.  Instead, I use array functions.  For example, ArrayAppend can combine two items into one, or add one item to another.  Check this out...

    doc.Person = ArrayAppend(doc.Person, doc.SubmittedBy) ' replaces lines 33 and 34 above

A note about ArrayAppend:  It only works when both arguments are arrays.  For example, this code will fail because the value we want to append is not an array...

    doc.Person = ArrayAppend(doc.Person, "New Value")

To work around this, I have a function in my standard library called ArrayAdd that can accept any scalar or array argument.  The code for the function is below.  Here is a simple agent you can use to test the function...

Sub Initialize
      Dim result As Variant
      Dim a As String, b As String, c As String
      a = "arrays"
      b = "are"
      c = "fun!"
      result = ArrayAdd(a, b)
      Msgbox Join(result, " ")
      result = ArrayAdd(result, c)
      Msgbox Join(result, " ")
End Sub
Public Function ArrayAdd(a1 As Variant, a2 As Variant) As Variant
	' ensure that both arguments are arrays.
	Dim array1 As Variant, array2 As Variant
	If (Isarray(a1)) Then
		array1 = a1
		Redim array1(0)
		array1(0) = a1
	End If
	If (Isarray(a2)) Then
		array2 = a2
		Redim array2(0)
		array2(0) = a2
	End If
	' ok to use ArrayAppend
	ArrayAdd = Arrayappend(array1, array2)
End Function

Open in new window

OK, you're really close.

The problem is on line #47...


Is the value of the first name in the field (index=0).


Is the entire contents of the item as an array, so just change line #47 to...


If you have multiple values in doc.Email_Address, you may also want to change line #46.

kali958Author Commented:
The email_address is only ONE address, they can only submit the call to one team and not multiple, so that works fine.

the issue for the CopyTo is when they want to copy a sr. rep and a supervisor on a call to review when there is a issue.

I am really sorry but I dont know what you mean by "Is the value of the first name in the field (index=0).

Would I do the following
Dim copylist as variant
set copylist =doc.CopyTo

??? oh i wish i understood this better but at least i am trying  :)
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

You don't need to do all of that.

My post was not very clear.  Let me explain.

When you access a document item, you are always using an array.  For example, this line...

    edoc.CopyTo = doc.CopyTo(0)

... is setting the CopyTo item in edoc to the first element of the CopyTo item in doc.

Document items are indexed just like arrays in C.  The first entry in the array has an index of zero, the second entry has an index of 1, etc...

So, doc.CopyTo(0) references the first entry in the item.  If you wanted the second entry, you would use doc.CopyTo(1).

If you want the entire array of item values, just leave off the index like this...

    edoc.CopyTo = doc.CopyTo

This assigns the entire contents of the CopyTo field regardless of how many entries are contained in the item.

I hope this helps.
kali958Author Commented:
OH I so get the (0) vs. the (1) now, i got that part

I did remove it so now it just says

edoc.CopyTo=doc.CopyTo and I sent a test email with two names in the CopyTo Field and it did send the email to the team email box but it now left the copy to field in the mail memo blank.

Do I still need to delcare the copyto field?  I remove all the dim/set for copylist out of the code.
>> "it did send the email to the team email box but it now left the copy to field in the mail memo blank."

Strange, that shouldn't happen.  That is expected for BCC, but not CC.  Is the team email box based on a standard email template or is it a custom application?

>> "Do I still need to declare the copyto field?"

Not sure what you mean here.  You don't have to actually declare fields or items in Notes.  One of the beautiful things about Notes is that you can add and remove fields/items on the fly.  This snippet illustrates what i mean...

    Dim memo as New NotesDocument(db)
    memo.Subject = "Hello"
    memo.SendTo = ""
    memo.SourceId = "009987665443321"
    Call memo.Send(False)

Notice above that I added an item to the document that the standard memo form does not support.  The code still works, and the memo will be delivered.  The SourceId value will not be visible on the memo form, but if you examine the memo's item values in the Property window, you will see the SourceId item and value.  I use this sometimes to locate memos that originated from different systems.  The mail database does not use the field, but I can write other code that identifies these memos in the user file.

Again, this is just a simple example of adding an item to a document without having to declare anything.

If you're still having problems and you want to post your most recent code, I'll be happy to take another look.
kali958Author Commented:
The team mailbox is running on the std7mail template. The database that is sending the email is a custom one I built.

Thank you for explaining that fields can be used in the script without a DIM/SET, that is probably where i was getting screwed up.

Would it help then if there was something like a dynmaic array with a redim on it due to there is no set amount in the CopyTo field. It could be 1 person or 10 people.
>> "Would it help then if there was something like a dynmaic array with a redim on it due to there is no set amount in the CopyTo field. It could be 1 person or 10 people."

Not sure what you're asking here.  Dynamic arrays are accomplished by declaring the variable as a variant.

For example,

Dim array As Variant
redim array(2)
array(0) = "item 1"
array(1) = "item 2"
array(2) = "item 3"
redim preserve array(ubound(array)+1) ' increase array size by one.
array(3) = "item 4"

You can use this array to set an item value...

doc.ItemName = array

You can also create arrays of mixed types, but you can't use those to set item values.

Dim array As Variant
array redim(2)
array(0) = "item 1"
array(1) = 1000
array(2) = new NotesDatabase("", "")
doc.ItemName = array ' ERROR!
kali958Author Commented:
What about

dim arrayCopyTo as Variant
arrayCopyTo = doc.CopyTo

edoc.CopyTo = arrayCopyTo ???

The book that was using was saying that dymanic array are not hard coded like the regular arrays where you have value 1, value 2, value 3 etc. but that for a multivalue field you need a dynamic array.
The book also talked a a redim and then i got lost
kali958Author Commented:
Thank you Bill - everything is up and working now. I did a few tests with multiple names in the CopyTo and everyone got a copy! The users are now happy.  

I did a mix between how you explained it and the examples I had to declare the array and call it for the mail memo. Thanks again, everything you explained totally made more sense then the book I was using.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.