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

Категории

© amp.flylib.com,