We help IT Professionals succeed at work.
Get Started

EMAIL with LOTUS SCRIPT

car701015
car701015 asked
on
616 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

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 17 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE