Friday, 16 September 2016

Quick IBM Notes Tip: LotusScript Function to Send Emails to Users Registered on a Profile Form with Information based on Documents in a View

Yesterday I posted a Tweet on Twitter regarding a LotusScript Function to send emails to users registered on a Profile Form with information based on documents in a View. Based on this Tweet I have had a number of requests to publish this LotusScript function on my blog.
Some remarks concerning the LotusScript function.
The LotusScript function uses a two fields which are present on the Profile form in the specified database (current database).
The first field on the Profile form, NotificationMembersEmail, concerns the persons to whom the Email is sent (Type Names - Editable - Allow multiple values). The second field on the Profile form, Footer, concerns the Email footer (Rich Text - Editable).
The function loops through all the documents in the specified View, retrieves the value of the specified Field Names, creates Email with a Text Line, the Values of Fields and an Email footer and finally sends the Email to the registered persons on the Profile form.
I included the sendEmail function in a Script Library. The function can be called from a sheduled Agent. Below the sendEmail LotusScript function.

Function sendEmail(doc As NotesDocument) As Boolean
Dim s As NotesSession
Dim db As NotesDatabase
Dim vdoc As NotesDocument
Dim pdoc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim view As NotesView
Dim footer As NotesRichTextItem

Set s = New NotesSession
Set db = s.CurrentDatabase
Set view = db.GetView("VIEWNAME")
Set doc = New NotesDocument(db)
Set pdoc = db.Getprofiledocument("ProfileForm")
Set footer = pdoc.GetFirstItem("Footer")

Dim datetim As New NotesDateTime( Now() )

'- prepare mail
If view.EntryCount <> 0 Then
doc.Form = "Memo"

'- Set recipient
doc.Principal = "SOMENAME"
doc.~$AltPrincipal = "SOMENAME"
doc.From = "SOMENAME"
doc.SendTo = pdoc.NotificationMembersEmail
doc.Subject = "TEXTSUBJECT" + " " + CStr(Now())

Set rtitem = New NotesRichTextItem( doc, "Body" )

Call rtitem.AppendText("TEXTLINE EMAIL")
Call rtitem.AddNewLine(1)

'collect all documents in View
Set vdoc = view.GetFirstDocument
Do Until vdoc Is Nothing
Call rtitem.AddNewline(1)
Call rtitem.AppendText(vdoc.FIELDNAME(0))
Call rtitem.AppendText(" - " & vdoc.FIELDNAME2(0))
Set vdoc = view.GetNextDocument(vdoc)

'add eEmail footer profile form
Call rtitem.AddNewline(3)
Call rtitem.AppendRTItem(footer)

Call doc.Send(False)
End If

End Function

The function is easily adjustable to your own insights and needs.

No comments:

Post a Comment