Objective
The objective of this sample is to create an agent that searches the documents in
a Domino database.
Time Required
Allow half an hour to create and run this agent.
Before You Begin
To build and run this sample you need to have Notes 4.6 or higher installed.
To prepare for the sample, follow the steps in the Domino Samples Overview.
Set up your Lotus Notes and VisualAge for Java environments to support the Domino AgentRunner by following the steps in Setting up for the AgentRunner and return to this sample.
Description
This sample agent runs against a database retrieving all documents which have the same
subject as the document you invoke the agent against. The agent will send you a mail
message containing a list of links to all documents related to a common subject. For
example, if you select a document with the subject Hello World and then invoke the agent,
a list of all the documents that contain the string 'Hello World' in the subject field
will be returned in a mail message, with a link to each document.
Export the .class File
To export the .class file from the com.ibm.ivj.examples.simpleagent package in
VisualAge for Java to the file system so it can be read by Notes:
When you export files to the file system, the directory path of the file is maintained.
For example, if you entered X:\VAJexport
as your export destination,
the SimpleAgent.class file will be in X:\VAJexport\com\ibm\ivj\examples\domino\simpleagent.
Create the Agent in Notes
For the AgentRunner to work in the IDE you have to provide it with a context for running
your agent. In this samples you run the agent in your Notes mail database but you
could create the agent in any database. To create an AgentContext document:
Running the Agent in Notes
Open the Java Console in Notes by selecting File - Tools - Show Java
Debug Console so you can monitor your agent. Select a document that has as
its subject the text string you want your agent to search for. From the Actions
menu of the Domino database, select SimpleAgent. The agent will run
but the session will return Null. An AgentContext document will be created in the
AgentRunner.nsf
Using the AgentRunner
Now you are ready to run the agent in the AgentRunner.
To run your agent from the Workbench:
The Domino AgentRunner will run your agent using the AgentContext document that you created in Notes.
Update your AgentContext (optional)
If you want to change which documents you want the agent to run against:
The Domino AgentRunner will run your agent with your updated agent context.
Create the Production Agent
When your agent runs without errors, you can create the production agent by
taking it out of 'Debug' mode.
Open your SimpleAgent class file in the Workbench. In the Source window, change what the class extends from lotus.notes.DebugAgentBase to lotus.notes.AgentBase. Click your SimpleAgent class in the All Projects window. You will be asked if you want to save your changes. Click Yes.
Export the .class File
Your agent is now in it's completed state and can be run in Notes. Export the .class
file to the file system using the Export SmartGuide. Open your agent in Notes and
reimport the SimpleAgent.class file.
Run the Agent in Notes
To run the agent, select a mail document with a common subject. Select your agent
from the Actions menu. The agent will run and send you a mail message
that contains all the documents in the database that contain the subject of the document
you ran the agent against. Open the mail message and select the links to the related
documents.