Agent to Manually Generate an Email Report

This example illustrates how to create an agent that generates a report. The agent is manually triggered by the user through an action button or the database menu. When executed, a report is generated and sent to the person who triggered the agent.

How It Works

After the agent is created, the user manually triggers execution of the agent through an action button or from the Action database menu. The agent iterates through all documents in the specified view and builds an email. After all documents have been processed, the report is emailed to the user who manually triggered the agent. The email message includes a document link and title for all documents processed.

Lets say you have a database with a view that contains open action items. Using this approach, you could generate an email report with document links. The report could then be forwarded to management or team members.

Implementation

To implement this solution, complete the following steps.

Step 1.

Create or select a view to be used when generating a report. Make note of the view name.

Step 2.

Select the Create > Design > Agent menu options to create the agent. When the properties dialog displays, give the agent a name such as Generate Report and set the Runtime Target to None. After these values are set, close the properties dialog.

Step 3.

Change the Language Selector from Simple action(s) to LotusScript. Add the following in the Initialize sections. Be sure to replace VIEW with the name of the view to be used to create the report. Also, to display a description next to each document link, replace FIELD with a valid text field from the form.

Sub Initialize
 Dim s As New NotesSession
 Dim db As NotesDatabase
 Dim view As NotesView
 Dim doc As NotesDocument
 Dim memo As NotesDocument
 Dim rtitem As NotesRichTextItem
 Dim PersonName As New NotesName(s.UserName)

 ---------------------------------------------------
  Set object values
  Replace VIEW with a valid View name
 ---------------------------------------------------
 Set db = s.CurrentDatabase
 Set memo = New NotesDocument (db)
 Set view = db.GetView("VIEW")
 Set doc = view.GetFirstDocument

 ---------------------------------------------------
  Begin processing
 ---------------------------------------------------

 If doc Is Nothing Then
 Print "Success: Agent ran, no items found"
 Else
 ---------------------------------------------------
  Create the newsletter
 ---------------------------------------------------
 memo.Form = "Memo"
 memo.SendTo = PersonName.Abbreviated
 memo.Subject = "Database Report"
 Set rtitem = New NotesRichTextItem(memo, "Body")
 Call rtitem.AddNewLine(1)
 Call rtitem.AppendText("Here is the requested report.")
 Call rtitem.AddNewLine(2)

 ---------------------------------------------------
  Add the newsletter items
  Replace FIELD with a valid field on the document
 ---------------------------------------------------
 While Not (doc Is Nothing)
 Call rtitem.AddNewLine(1)
 Call rtitem.AppendDocLink(doc, db.Title)
 Call rtitem.AppendText(" -- " + doc.FIELD(0))
 Set doc = view.GetNextDocument(doc)
 Wend

 ---------------------------------------------------
  Close and send the report
 ---------------------------------------------------
 Call rtitem.AddNewLine(3)
 Call rtitem.AppendText("<---- END OF REPORT ---->")
 Call memo.Send (False)

 Print "Success: Report generated and sent. "
 End If

End Sub


Note

Depending on the database security settings, an Execution Control List (ECL) message may be displayed for some users. Users will need to select an execution option, such as Run Once, for the agent to run. See Chapter 19, "Security," for additional information pertaining to database security as well as how to "sign" a database.


Figure 16.3 shows a sample email report.

Figure 16.3. Sample email report with document links




An Introduction to the Lotus Domino Tool Suite

Getting Started with Designer

Navigating the Domino Designer Workspace

Domino Design Elements

An Introduction to Formula Language

An Introduction to LotusScript

Fundamentals of a Notes Application

Calendar Applications

Collaborative Applications

Reference Library Applications

Workflow Applications

Web Applications

Design Enhancements Using LotusScript

Design Enhancements Using Formula Language

View Enhancements

Sample Agents

Miscellaneous Enhancements and Tips for Domino Databases

Data Management

Security

Application Deployment and Maintenance

Troubleshooting

Appendix A. Online Project Files and Sample Applications

Appendix B. IBM® Lotus® Notes® and Domino®Whats Next?



Lotus Notes Developer's Toolbox(c) Tips for Rapid and Successful Deployment
Lotus Notes Developers Toolbox: Tips for Rapid and Successful Deployment
ISBN: 0132214482
EAN: 2147483647
Year: N/A
Pages: 293
Authors: Mark Elliott

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net