[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

EMAIL with LOTUS SCRIPT

Posted on 2010-03-23
17
Medium Priority
?
587 Views
Last Modified: 2013-11-16

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

0
Comment
Question by:car701015
  • 8
  • 6
  • 2
  • +1
17 Comments
 
LVL 19

Expert Comment

by:madheeswar
ID: 28325442
instead of this:
SendTo(CountSend) = tmpSendTo(Index)
try
SendTo(CountSend) = tmpSendTo(Index) + ";"

0
 
LVL 19

Expert Comment

by:madheeswar
ID: 28325513
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
 
LVL 63

Expert Comment

by:Zvonko
ID: 28326167
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
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
LVL 63

Expert Comment

by:Zvonko
ID: 28326264
Give also an example how your values for the field "sales_person" look alike.
0
 

Author Comment

by:car701015
ID: 28326929
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
 

Author Comment

by:car701015
ID: 28328196
The field name is 'notify' that could contain a mail group or multiple people
0
 

Author Comment

by:car701015
ID: 28330663
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
 

Author Comment

by:car701015
ID: 28333005
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
 

Author Comment

by:car701015
ID: 28333035
Updating Points
0
 
LVL 19

Expert Comment

by:madheeswar
ID: 28338900
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
 
LVL 19

Expert Comment

by:madheeswar
ID: 28338943
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
 
LVL 22

Accepted Solution

by:
Bill-Hanson earned 2000 total points
ID: 28342971
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
 

Author Closing Comment

by:car701015
ID: 31705928
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
 
LVL 19

Expert Comment

by:madheeswar
ID: 28397137
I gave almost the same answer.

Except I made it as array.

:(
0
 

Author Comment

by:car701015
ID: 28415818
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
 
LVL 19

Expert Comment

by:madheeswar
ID: 28416047
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
 

Author Comment

by:car701015
ID: 28420981
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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Suggested Courses

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question