troubleshooting Question

EMAIL with LOTUS SCRIPT

Avatar of car701015
car701015 asked on
Lotus IBM
17 Comments1 Solution617 ViewsLast Modified:

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

ASKER CERTIFIED SOLUTION
Bill-Hanson

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 17 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 17 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros