EMAIL with LOTUS SCRIPT


Good day members,

I have the following code, that USED to work perfectly well, then it stopped... The issue I have is when I have multiple people to be mailed in the one field... Only the first person gets it or none...

' Collect the Names of the people to send to (THIS IS WHERE I THINK I HAVE AN ISSUE AND NEEDS HELP PLEASE)
tmpSendTo = Split(doc.getFirstItem("sales_person").text,";")
For Index = 0 To Ubound(tmpSendTo)
On Error Resume Next
If (tmpSendTo(Index) <> session.UserName) Then
Dim Countsend As Integer
CountSend = Ubound(SendTo) + 1
Redim SendTo(CountSend)
SendTo(CountSend) = tmpSendTo(Index)
End If

** CODE STARTS **

Sub Click(Source As Button)

Dim session As New NotesSession
Dim ws As New NotesUIWorkspace

Dim uiDoc As NotesUIDocument
Set uiDoc = ws.CurrentDocument

Dim SendTo() As Variant
Dim tmpSendTo As Variant
Dim SendFrom As String

'================================================================================================
' Collect Information from current document
'================================================================================================
Dim GetName As NotesName

Dim doc As NotesDocument

Set doc = uiDoc.Document

If Not doc.HasItem("sales_person") Then
Msgbox("Please update Sales Executive details")
Exit Sub
End If

If doc.HasItem("customer") Then
Customer = doc.GetFirstItem("Customer").text
End If

If doc.HasItem("gci") Then
gci = doc.GetFirstItem("gci").text
End If

If doc.HasItem("date_account_opened") Then
date_account_opened = doc.GetFirstItem("date_account_opened").text
End If

If doc.HasItem("vat_number") Then
vat_number = doc.GetFirstItem("vat_number").text
End If

If doc.HasItem("customs_code") Then
customs_code = doc.GetFirstItem("customs_code").text
End If

Set GetName = session.CreateName(session.UserName)
sendfrom = GetName.Common

' Collect the Names of the people to send to
tmpSendTo = Split(doc.getFirstItem("sales_person").text,";")
For Index = 0 To Ubound(tmpSendTo)
On Error Resume Next
If (tmpSendTo(Index) <> session.UserName) Then
Dim Countsend As Integer
CountSend = Ubound(SendTo) + 1
Redim SendTo(CountSend)
SendTo(CountSend) = tmpSendTo(Index)
End If
Next

' Need to save document before we can link it
If uiDoc.EditMode = True Then
uiDoc.Save
uiDoc.EditMode = False
End If

'================================================================================================
' Send a Memo
'================================================================================================

Dim db As NotesDatabase
Set db = session.CurrentDatabase

Dim docMemo As NotesDocument
Set docMemo = db.CreateDocument

Dim FromPeople As String

docMemo.Form = "Memo"
docMemo.Subject = "New Account Opened:" + " " + Customer + ", " + "Account Number:"+ " " + gci

docMemo.Principal = SendFrom

'Setting the mail groups to notify new account opened
FromPeople = doc.getFirstItem("notify").text
docMemo.blindCopyTo = Split(FromPeople,";")

'Also Blind Copy the sender for record purposes
BCC_sender = GetName.Common
docMemo.blindCopyTo = Split(BCC_Sender,";")

Dim rtitemBody As NotesRichTextItem
Set rtitemBody = docMemo.CreateRichTextItem("Body")
Call rtitemBody.AppendText(" ** This is a Systems Generated mail ** ")
Call rtitemBody.AddNewLine(2)
Call rtitemBody.AppendText("Please be advised the account has been opened for the following Customer:")
Call rtitemBody.AddNewLine(2)
Call rtitemBody.AppendText("Customer Name: ")
Call rtitemBody.AppendText(doc.GetFirstItem("customer").Text)
Call rtitemBody.AddNewLine(1)
Call rtitemBody.AppendText("Products: ")
Call rtitemBody.AppendText(doc.GetFirstItem("products").Text)
Call rtitemBody.AddNewLine(1)
Call rtitemBody.AppendText("Account Number / GCI: ")
Call rtitemBody.AppendText(doc.GetFirstItem("gci").Text)
Call rtitemBody.AddNewLine(1)
Call rtitemBody.AppendText("Date Account Opened: ")
Call rtitemBody.AppendText(doc.GetFirstItem("date_account_opened").Text)
Call rtitemBody.AddNewLine(1)
Call rtitemBody.AppendText("Payment Terms: ")
Call rtitemBody.AppendText(doc.GetFirstItem("payment_terms").Text)
Call rtitemBody.AddNewLine(2)
Call rtitemBody.AppendText("Vat Number: ")
Call rtitemBody.AppendText(doc.GetFirstItem("vat_number").Text)
Call rtitemBody.AddNewLine(1)
Call rtitemBody.AppendText("Customs Code: ")
Call rtitemBody.AppendText(doc.GetFirstItem("customs_code").Text)
Call rtitemBody.AddNewLine(2)
Call rtitemBody.AppendText("Accounts Comments: ")
Call rtitemBody.AppendText(doc.GetFirstItem("history").Text)
Call rtitemBody.AddNewLine(2)
Call rtitemBody.AppendText("Link to Customer Profile:--> ")
Call rtitemBody.AppendDocLink(doc,Customer)
Call rtitemBody.AddNewLine(6)

Call rtitemBody.AppendText("Best Regards ")
Call rtitemBody.AddNewLine(2)
Call rtitemBody.AppendText(GetName.Common)
Call rtitemBody.AddNewLine(1)
Call rtitemBody.AppendText("xxxxxxx")

Call docMemo.Send(False , SendTo )
'================================================================================================

uiDoc.Close

End Sub

** CODE ENDS **



Best Regards

car701015
Sub Click(Source As Button)

Dim session As New NotesSession
Dim ws As New NotesUIWorkspace

Dim uiDoc As NotesUIDocument 
Set uiDoc = ws.CurrentDocument

Dim SendTo() As Variant
Dim tmpSendTo As Variant
Dim SendFrom As String

'================================================================================================
' Collect Information from current document
'================================================================================================
Dim GetName As NotesName 

Dim doc As NotesDocument 

Set doc = uiDoc.Document

If Not doc.HasItem("sales_person") Then
Msgbox("Please update Sales Executive details") 
Exit Sub 
End If

If doc.HasItem("customer") Then
Customer = doc.GetFirstItem("Customer").text
End If

If doc.HasItem("gci") Then
gci = doc.GetFirstItem("gci").text
End If

If doc.HasItem("date_account_opened") Then
date_account_opened = doc.GetFirstItem("date_account_opened").text
End If

If doc.HasItem("vat_number") Then
vat_number = doc.GetFirstItem("vat_number").text
End If

If doc.HasItem("customs_code") Then
customs_code = doc.GetFirstItem("customs_code").text
End If

Set GetName = session.CreateName(session.UserName)
sendfrom = GetName.Common

' Collect the Names of the people to send to
tmpSendTo = Split(doc.getFirstItem("sales_person").text,";")
For Index = 0 To Ubound(tmpSendTo)
On Error Resume Next 
If (tmpSendTo(Index) <> session.UserName) Then
Dim Countsend As Integer
CountSend = Ubound(SendTo) + 1
Redim SendTo(CountSend)
SendTo(CountSend) = tmpSendTo(Index)
End If
Next

' Need to save document before we can link it
If uiDoc.EditMode = True Then
uiDoc.Save
uiDoc.EditMode = False
End If

'================================================================================================
' Send a Memo 
'================================================================================================

Dim db As NotesDatabase
Set db = session.CurrentDatabase

Dim docMemo As NotesDocument 
Set docMemo = db.CreateDocument

Dim FromPeople As String

docMemo.Form = "Memo"
docMemo.Subject = "New Account Opened:" + " " + Customer + ", " + "Account Number:"+ " " + gci

docMemo.Principal = SendFrom

'Setting the mail groups to notify new account opened 
FromPeople = doc.getFirstItem("notify").text
docMemo.blindCopyTo = Split(FromPeople,";")

'Also Blind Copy the sender for record purposes
BCC_sender = GetName.Common
docMemo.blindCopyTo = Split(BCC_Sender,";")

Dim rtitemBody As NotesRichTextItem 
Set rtitemBody = docMemo.CreateRichTextItem("Body")
Call rtitemBody.AppendText(" ** This is a Systems Generated mail ** ") 
Call rtitemBody.AddNewLine(2)
Call rtitemBody.AppendText("Please be advised the account has been opened for the following Customer:") 
Call rtitemBody.AddNewLine(2)
Call rtitemBody.AppendText("Customer Name: ") 
Call rtitemBody.AppendText(doc.GetFirstItem("customer").Text)
Call rtitemBody.AddNewLine(1)
Call rtitemBody.AppendText("Products: ") 
Call rtitemBody.AppendText(doc.GetFirstItem("products").Text)
Call rtitemBody.AddNewLine(1)
Call rtitemBody.AppendText("Account Number / GCI: ") 
Call rtitemBody.AppendText(doc.GetFirstItem("gci").Text)
Call rtitemBody.AddNewLine(1)
Call rtitemBody.AppendText("Date Account Opened: ") 
Call rtitemBody.AppendText(doc.GetFirstItem("date_account_opened").Text)
Call rtitemBody.AddNewLine(1)
Call rtitemBody.AppendText("Payment Terms: ") 
Call rtitemBody.AppendText(doc.GetFirstItem("payment_terms").Text)
Call rtitemBody.AddNewLine(2)
Call rtitemBody.AppendText("Vat Number: ") 
Call rtitemBody.AppendText(doc.GetFirstItem("vat_number").Text)
Call rtitemBody.AddNewLine(1)
Call rtitemBody.AppendText("Customs Code: ") 
Call rtitemBody.AppendText(doc.GetFirstItem("customs_code").Text)
Call rtitemBody.AddNewLine(2)
Call rtitemBody.AppendText("Accounts Comments: ") 
Call rtitemBody.AppendText(doc.GetFirstItem("history").Text)
Call rtitemBody.AddNewLine(2)
Call rtitemBody.AppendText("Link to Customer Profile:--> ") 
Call rtitemBody.AppendDocLink(doc,Customer) 
Call rtitemBody.AddNewLine(6)

Call rtitemBody.AppendText("Best Regards ") 
Call rtitemBody.AddNewLine(2)
Call rtitemBody.AppendText(GetName.Common) 
Call rtitemBody.AddNewLine(1)
Call rtitemBody.AppendText("xxxxxxx") 

Call docMemo.Send(False , SendTo )
'================================================================================================

uiDoc.Close

End Sub

Open in new window

car701015Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

madheeswarCommented:
instead of this:
SendTo(CountSend) = tmpSendTo(Index)
try
SendTo(CountSend) = tmpSendTo(Index) + ";"

0
madheeswarCommented:
Also, check what SendTo is populating in the end. Is it having one value or multi value as an array.
Check using debugger. Alternatively, you can send each email in the for loop.
0
ZvonkoSystems architectCommented:
Hello,

extend the second parameter for the Split() function and add more characters for what the field value should be splitted.
Like this:

tmpSendTo = Split(doc.getFirstItem("sales_person").text,";, ")


0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

ZvonkoSystems architectCommented:
Give also an example how your values for the field "sales_person" look alike.
0
car701015Author Commented:
Nothing was populated... it was blank... I only get the mail as the BCC receipient...

however, I think I might have issue here

My field where I capture the names of the people is called "notify" I somehow by passes this and dont know how to correct it... when I send out the memo I somehow messes things up again... could you check that portion out for me??
Set GetName = session.CreateName(session.UserName)
	sendfrom = GetName.Common
	
	' Collect the Names of the people to send to
	tmpSendTo = Split(doc.getFirstItem("sales_person").text,";")
	For Index = 0 To Ubound(tmpSendTo)
		On Error Resume Next		
		If (tmpSendTo(Index) <> session.UserName) Then
			Dim Countsend As Integer
			CountSend = Ubound(SendTo) + 1
'			Redim SendTo(CountSend)
			Redim Preserve SendTo(CountSend)
			'SendTo(CountSend) = tmpSendTo(Index)
			SendTo(CountSend) = tmpSendTo(Index) + ";"
		End If
	Next
	
	' Need to save document before we can link it
	If uiDoc.EditMode = True Then
		uiDoc.Save
		uiDoc.EditMode = False
	End If
	
	'================================================================================================
	' Send a Memo 
	'================================================================================================
	
	Dim db As NotesDatabase
	Set db = session.CurrentDatabase
	
	Dim docMemo As NotesDocument 
	Set docMemo = db.CreateDocument
	
	Dim FromPeople As String
	
	docMemo.Form = "Memo"
	docMemo.Subject = "New Account Opened:" + " " + Customer  + ", " +  "Account Number:"+ " " + gci
	
	docMemo.Principal = SendFrom
	
	'Setting the mail groups to notify new account opened	
	FromPeople = doc.getFirstItem("notify").text
	docMemo.blindCopyTo = Split(FromPeople,";")

Open in new window

0
car701015Author Commented:
The field name is 'notify' that could contain a mail group or multiple people
0
car701015Author Commented:
I ran Debug and the values does show as follows

VALUES
[0] "Christo Du Toit",....... VARIANT
[1] "CN=Admin-JNB/OU=XXX/O=xxxxxxxxx"         STRING
[2] "CN=Willie Boshoff/OU=XXX/O=xxxxxxxxx"           STRING

then under PARENT it shows

"Christo Du Toit;CN=Admin-XXX/OU=XXX/O=xxxxxxxxx;CN=Willie Boshoff/OU=XXX/O=xxxxxxxxx"
0
car701015Author Commented:
Hi Experts... I changed the code slightly  and managed to get ONE name specified in 'notify' field sent a mail... See the following :) I moved the for loop down to the memo section and change the "wrong declared field" to the correct being 'notify' The ONLY remaining thing now is that it still doesnt show all the names...



Sub Click(Source As Button)
      
      Dim session As New NotesSession
      Dim ws As New NotesUIWorkspace
      
      Dim uiDoc As NotesUIDocument
      Set uiDoc = ws.CurrentDocument
      
      Dim SendTo() As Variant
      Dim tmpSendTo As Variant
      Dim SendFrom As String
      
'================================================================================================
' Collect Information from current document
'================================================================================================
      Dim GetName As NotesName
      
      Dim doc As NotesDocument
      
      Set doc = uiDoc.Document
      
      If Not doc.HasItem("sales_person") Then
            Msgbox("Please update Sales Executive details")
            Exit Sub
      End If
      
      If doc.HasItem("customer") Then
            Customer = doc.GetFirstItem("Customer").text
      End If
      
      If doc.HasItem("gci") Then
            gci = doc.GetFirstItem("gci").text
      End If
      
      If doc.HasItem("date_account_opened") Then
            date_account_opened = doc.GetFirstItem("date_account_opened").text
      End If
      
      If doc.HasItem("vat_number") Then
            vat_number = doc.GetFirstItem("vat_number").text
      End If
      
      If doc.HasItem("customs_code") Then
            customs_code = doc.GetFirstItem("customs_code").text
      End If
      
      Set GetName = session.CreateName(session.UserName)
      sendfrom = GetName.Common
      
' Need to save document before we can link it
      If uiDoc.EditMode = True Then
            uiDoc.Save
            uiDoc.EditMode = False
      End If
      
'================================================================================================
' Send a Memo
'================================================================================================
      
      Dim db As NotesDatabase
      Set db = session.CurrentDatabase
      
      Dim docMemo As NotesDocument
      Set docMemo = db.CreateDocument
      
      Dim FromPeople As String
      
      docMemo.Form = "Memo"
      docMemo.Subject = "New Account Opened:" + " " + Customer + ", " + "Account Number:"+ " " + gci
      
      docMemo.Principal = SendFrom
      
'Setting the mail groups to notify new account opened
      'FromPeople = doc.getFirstItem("notify").text
      'docMemo.blindCopyTo = Split(FromPeople,";")
      
      ' Collect the Names of the people to send to
'      tmpSendTo = Split(doc.getFirstItem("notify").text,";")
      tmpSendTo = Split(doc.getFirstItem("notify").text,";, ")
      
      For Index = 0 To Ubound(tmpSendTo)
            On Error Resume Next
            If (tmpSendTo(Index) <> session.UserName) Then
                  Dim Countsend As Integer
                  CountSend = Ubound(SendTo) + 1
                  Redim SendTo(CountSend)
                  SendTo(CountSend) = tmpSendTo(Index)
            End If      
            
      Next
      
'Also Blind Copy the sender for record purposes
      BCC_sender = GetName.Common
      docMemo.blindCopyTo = Split(BCC_Sender,";")
      
      
0
car701015Author Commented:
Updating Points
0
madheeswarCommented:
In your original code use below:
Dim Countsend As Integer

For Index = 0 To Ubound(tmpSendTo)
On Error Resume Next
If (tmpSendTo(Index) <> session.UserName) Then

CountSend = Ubound(SendTo) + 1
Redim SendTo(CountSend)
SendTo(CountSend) = tmpSendTo(Index)
End If
Next
0
madheeswarCommented:
Else use below code:
Dim SendTo() As array
Dim Countsend As Integer
Countsend = 0
For Index = 0 To Ubound(tmpSendTo)
On Error Resume Next
If (tmpSendTo(Index) <> session.UserName) Then
Redim SendTo(CountSend)
SendTo(CountSend) = tmpSendTo(Index)
CountSend = CountSend  + 1
End If
Next

Call docMemo.Send(False , FullTrim(SendTo ))
0
Bill-HansonCommented:
The problem is that you are not Preserving your array values.

In your loop, you are growing the size of your dynamic array (SendTo), but you are not preserving the existing values in the array.  So every time you grow the array using Redim, you are loosing all of the other addresses you have already collected.

In order to keep the existing values in your dynamic array, you need to use the 'Preserve' keyword along with 'Redim'.

Here is how I would handle this...
Dim SendTo As Variant
Dim Countsend As Integer
Countsend = 0
On Error Resume Next 
For Index = 0 To UBound(tmpSendTo)
	If (tmpSendTo(Index) <> session.UserName) Then
		ReDim Preserve SendTo(CountSend)
		SendTo(CountSend) = tmpSendTo(Index)
		CountSend = CountSend  + 1
	End If
Next

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
car701015Author Commented:
After many tries and various other suggestions, I still ended up with just a single name that pulled through... Bill's answer fixed it immediately and although he was spot on, I would like to thank each and every one who helped me on this... You guys ROCK!!!

To Bill, thanks mate... spot on and your solution description helped me to understand what I did wrong... I am VERY VERY new at this, so please accept my humble gratitude!

Best regards

0
madheeswarCommented:
I gave almost the same answer.

Except I made it as array.

:(
0
car701015Author Commented:
Thanks Master... I have tried it, somewhere it still only returned just one name... however, your valuable input has also taught me a lot... thanks
0
madheeswarCommented:
Yep....I have not used Preserve in Redim. I had it in my mind and not put it in to the code.
I am stupid. :(
0
car701015Author Commented:
Well think of it this way madheeswar, the Guru then helped all of us out :) no shame in that :) you still a master and that is still no mean feat :)

Cheers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.