car701015
asked on
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("sa
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"
Msgbox("Please update Sales Executive details")
Exit Sub
End If
If doc.HasItem("customer") Then
Customer = doc.GetFirstItem("Customer
End If
If doc.HasItem("gci") Then
gci = doc.GetFirstItem("gci").te
End If
If doc.HasItem("date_account_
date_account_opened = doc.GetFirstItem("date_acc
End If
If doc.HasItem("vat_number") Then
vat_number = doc.GetFirstItem("vat_numb
End If
If doc.HasItem("customs_code"
customs_code = doc.GetFirstItem("customs_
End If
Set GetName = session.CreateName(session
sendfrom = GetName.Common
' Collect the Names of the people to send to
tmpSendTo = Split(doc.getFirstItem("sa
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")
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
Call rtitemBody.AppendText(" ** This is a Systems Generated mail ** ")
Call rtitemBody.AddNewLine(2)
Call rtitemBody.AppendText("Ple
Call rtitemBody.AddNewLine(2)
Call rtitemBody.AppendText("Cus
Call rtitemBody.AppendText(doc.
Call rtitemBody.AddNewLine(1)
Call rtitemBody.AppendText("Pro
Call rtitemBody.AppendText(doc.
Call rtitemBody.AddNewLine(1)
Call rtitemBody.AppendText("Acc
Call rtitemBody.AppendText(doc.
Call rtitemBody.AddNewLine(1)
Call rtitemBody.AppendText("Dat
Call rtitemBody.AppendText(doc.
Call rtitemBody.AddNewLine(1)
Call rtitemBody.AppendText("Pay
Call rtitemBody.AppendText(doc.
Call rtitemBody.AddNewLine(2)
Call rtitemBody.AppendText("Vat
Call rtitemBody.AppendText(doc.
Call rtitemBody.AddNewLine(1)
Call rtitemBody.AppendText("Cus
Call rtitemBody.AppendText(doc.
Call rtitemBody.AddNewLine(2)
Call rtitemBody.AppendText("Acc
Call rtitemBody.AppendText(doc.
Call rtitemBody.AddNewLine(2)
Call rtitemBody.AppendText("Lin
Call rtitemBody.AppendDocLink(d
Call rtitemBody.AddNewLine(6)
Call rtitemBody.AppendText("Bes
Call rtitemBody.AddNewLine(2)
Call rtitemBody.AppendText(GetN
Call rtitemBody.AddNewLine(1)
Call rtitemBody.AppendText("xxx
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
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.
Check using debugger. Alternatively, you can send each email in the for loop.
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("sa les_person ").text,"; , ")
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("sa
Give also an example how your values for the field "sales_person" look alike.
ASKER
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??
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,";")
ASKER
The field name is 'notify' that could contain a mail group or multiple people
ASKER
I ran Debug and the values does show as follows
VALUES
[0] "Christo Du Toit",....... VARIANT
[1] "CN=Admin-JNB/OU=XXX/O=xxx xxxxxx" 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 "
VALUES
[0] "Christo Du Toit",....... VARIANT
[1] "CN=Admin-JNB/OU=XXX/O=xxx
[2] "CN=Willie Boshoff/OU=XXX/O=xxxxxxxxx
then under PARENT it shows
"Christo Du Toit;CN=Admin-XXX/OU=XXX/O
ASKER
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").te xt
End If
If doc.HasItem("date_account_ opened") Then
date_account_opened = doc.GetFirstItem("date_acc ount_opene d").text
End If
If doc.HasItem("vat_number") Then
vat_number = doc.GetFirstItem("vat_numb er").text
End If
If doc.HasItem("customs_code" ) Then
customs_code = doc.GetFirstItem("customs_ code").tex t
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("no tify").tex t,";")
tmpSendTo = Split(doc.getFirstItem("no tify").tex t,";, ")
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,";")
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"
Msgbox("Please update Sales Executive details")
Exit Sub
End If
If doc.HasItem("customer") Then
Customer = doc.GetFirstItem("Customer
End If
If doc.HasItem("gci") Then
gci = doc.GetFirstItem("gci").te
End If
If doc.HasItem("date_account_
date_account_opened = doc.GetFirstItem("date_acc
End If
If doc.HasItem("vat_number") Then
vat_number = doc.GetFirstItem("vat_numb
End If
If doc.HasItem("customs_code"
customs_code = doc.GetFirstItem("customs_
End If
Set GetName = session.CreateName(session
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")
'docMemo.blindCopyTo = Split(FromPeople,";")
' Collect the Names of the people to send to
' tmpSendTo = Split(doc.getFirstItem("no
tmpSendTo = Split(doc.getFirstItem("no
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,";")
ASKER
Updating Points
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
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
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 ))
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 ))
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
I gave almost the same answer.
Except I made it as array.
:(
Except I made it as array.
:(
ASKER
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
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. :(
I am stupid. :(
ASKER
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
Cheers
SendTo(CountSend) = tmpSendTo(Index)
try
SendTo(CountSend) = tmpSendTo(Index) + ";"