|
||||
|
||||
To begin, create a Lotus Notes profile document with the following fields:
- Function (dialog list/text) For example: Intimation
- Subject (rich-text) For example: <Name> - <ID>
- Body (rich-text) For example: Dear <Name>, your letter has been delivered. Thanks, <AdmName>
- Recipients (Name) For example: xyz@abc.com
From here, we would know the functionality for which the LotusScript code is being written. Just replace the tags with the data in the Lotus Notes database. The LotusScript code below has been written in the action button of a Lotus Notes form.
Here is a list of parameters used in the LotusScript code:
- vwMP: This is the view of the mail profile.
- MP_Subject: This is the "Subject" field in the mail profile document.
- MP_Body: This is the "Body" field in mail profile document.
- MP_SendTo, MP_Cc: These are the "To" and "CC" fields in the mail profile document.
- Name: This is the value of the "Name" field in the current document.
- ID: This is the value of the ID field in the current Lotus Notes document.
- AdmName: This is the value of the "Admin Name" field in the current Lotus Notes document.
Finally, here is my LotusScript code:
sub click(Source as Button)
dim ws as new notesuiworkspace
dim s as new notessession
dim uidoc as notesuidocument
dim db as notesdatabase
Dim doc As NotesDocument
Dim maildoc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim rtitem1 As NotesRichTextItem
Dim rtnav As NotesRichTextNavigator
Dim rtrange As NotesRichTextRange
Dim mvw As NotesView
Dim mdoc As NotesDocument
Dim searchString, replaceString As Variant
Set db=s.CurrentDatabase
Set uidoc=ws.CurrentDocument
Set doc=uidoc.Document
Set mvw=db.GetView("vwMP")
Set mdoc=mvw.GetDocumentByKey
("Intimation",0) Set maildoc=
New NotesDocument(db) Set maildoc=
db.CreateDocument() maildoc.
DeliveryPriority="H"
Set rtitem1=mdoc.GetFirstItem
("MP_Subject")
Set rtnav=rtitem1.CreateNavigator
searchString="<Name>"
replaceString=doc.Name(0)
Call rtnav.FindFirstElement(RTELEM_
TYPE_TEXTPARAGRAPH)
Set rtrange=rtitem1.CreateRange
While rtrange.FindAndReplace(searchString,
replaceString, RT_FIND_CASEINSENSITIVE) > 0
Call rtitem1.Update Wend
searchString="<ID>"
replaceString=doc.ID(0)
Call rtnav.FindFirstElement (RTELEM_
TYPE_TEXTPARAGRAPH)
Set rtrange=rtitem1.CreateRange
While rtrange.FindAndReplace(searchString,
replaceString, RT_FIND_CASEINSENSITIVE) > 0
Call rtitem1.Update Wend
maildoc.Subject=rtitem1.GetUnformattedText()
Set rtitem1=mdoc.GetFirstItem("MP_Body")
Set rtnav=rtitem1.CreateNavigator
searchString="<Name>"
replaceString=doc.Name(0)
Call rtnav.FindFirstElement(RTELEM_
TYPE_TEXTPARAGRAPH)
Set rtrange=rtitem1.CreateRange
While rtrange.FindAndReplace(searchString,
replaceString, RT_FIND_CASEINSENSITIVE) > 0
Call rtitem1.Update
Wend
searchString="<AdmName>"
replaceString=doc.AdmName(0)
Call rtnav.FindFirstElement(RTELEM_TYPE_
TEXTPARAGRAPH)
Set rtrange=rtitem1.CreateRange
While rtrange.FindAndReplace(searchString,
replaceString, RT_FIND_CASEINSENSITIVE) > 0
Call rtitem1.Update Wend
Set rtitem=New NotesRichTextItem(maildoc,"Body")
Call rtitem.AppendRTItem(rtitem1)
maildoc.sendTo=mdoc.MP_SendTo(0)
if MP_Cc(0)<>"" then
maildoc.copyTo=mdoc.MP_CopyTo(0)
end if Call maildoc.Send(False,False)
Msgbox "Mail has been sent successfully",
MB_OK,"Lotus Notes"
End Sub
Here is a simpler way to get the Lotus Notes profile document info:
Dim profileDoc as NotesDocument
Then
'>>> GET HANDLE TO
PROFILE DOCUMENTS
Set profileDoc = db.GetProfileDocument
( "pfDB" ) 'this is the name of the
profile document
If profileDoc Is Nothing Then
' >>> RAISE ERROR
eventName = " - - cannot get
handle to profile document"
Call Log_Event( eventName )
Error 1001, "User Defined Error"
Else
'>>> DATA FROM
PROFILE DOC
MemoSubj =
profileDoc.pfEmpSubject(0)
MemoBody =
profiledoc.pfNewEmpHeading(0)
Ron S.
******************************************
This LotusScript code is very simple, but the email is not signed and not encrypted in accordance to the Lotus Notes user settings. The attributes in the mail settings of the Lotus Notes user has not been considered.
Francois D.
Do you have comments on this tip? Let us know.
This tip was submitted to the SearchDomino.com tip library by member Manikandan Sv. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.
This was first published in October 2007