[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2109
  • Last Modified:

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
	Call uidoc.save
	
	doc.Status="Forwarded"
	doc.Status_Final="Closed - Forwarded"
	doc.Date_Forward=Now
	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
	
	doc.Comments=T
	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" )
	parent.Close
	
End Sub

Open in new window

0
kali958
Asked:
kali958
  • 5
  • 5
1 Solution
 
Bill-HansonCommented:
OK, you're really close.

The problem is on line #47...

    doc.CopyTo(0)

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

    doc.CopyTo

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

    doc.CopyTo

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

0
 
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
edoc.CopyTo=copylist

??? oh i wish i understood this better but at least i am trying  :)
0
 
Bill-HansonCommented:
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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.
0
 
Bill-HansonCommented:
>> "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 = "user@domain.com"
    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.
0
 
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.
0
 
Bill-HansonCommented:
>> "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!
0
 
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
0
 
Bill-HansonCommented:
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)
Loop

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
	Else
		Redim array1(0)
		array1(0) = a1
	End If
	If (Isarray(a2)) Then
		array2 = a2
	Else
		Redim array2(0)
		array2(0) = a2
	End If
	' ok to use ArrayAppend
	ArrayAdd = Arrayappend(array1, array2)
End Function

Open in new window

0
 
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.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now