Sample: Creating a To Do Agent

Objective
To create a Notes agent that uses Java AWT and NOI.

Time Required
Allow half an hour to run this sample with its supplied content and look over the output.

Before You Begin
To run this sample you need the following products:

Follow the steps in the Domino Samples Overview to prepare for the sample.

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 automatically checks your To do list once per day for any items that are due. A mail message will then be sent to the owners of the due items reminding them that a task is due that day.

Export the .class File
To export the .class file from the com.ibm.ivj.examples.domino.todoagent package in VisualAge for Java to the file system so it can be read by Notes:

  1. Open the IBM Domino Examples project in the Workbench and expand the com.ibm.ivj.examples.domino.todoagent package. 
  2. Click the ToDoAgent class with mouse button 2.
  3. Select Export.  The Export SmartGuide will open.
  4. Select the Directory radio button as your export destination.  Click Next.
  5. In the Directory text field, enter a location in the file system where you want to export the .class file.
  6. Select the .class checkbox and click Details
  7. Select the IBM Domino Examples and the ToDoAgent::com.ibm.ivj.examples.domino.todoagent checkboxes.  Click OK.
  8. Deselect the .java and resource checkboxes if they are selected.
  9. Click Finish.

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 ToDoAgent.class file will be in X:\VAJexport\com\ibm\ivj\examples\domino\todoagent.

Follow These Steps in Notes 4.6 to Set Up the Agent.

  1. Open your mail database.
  2. Select Agent from the Create menu.
  3. Enter a name for the agent, such as CheckTodo
  4. Select On Schedule Daily from the drop-down list When should this agent run.
  5. Click the Schedule button.
  6. From the Schedule window, enter a time for the agent to run, select the Don't run on weekends check box, and have the agent run on your Local database.
  7. Click OK.
  8. From the Which documents should it act on pull-down menu, select All documents in database.
  9. Click the Add Search button and select By Form Used as the condition
  10. Select Task as the form type and click OK.
  11. Select the java radio button for what should this agent run.
  12. Click the import class files button.
  13. Select the ToDoAgent.class file.
  14. Click Add.
  15. Click OK.
  16. Press the Esc key to close the Create Agent window. You will be asked if you want to save your changes.
  17. Click Yes.

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.  From the Actions menu of the Domino database, select ToDoAgent.  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:

  1. Open the Console window by selecting Window - Console.  This window will show the status of your agent.
  2. Select the ToDoAgent class with mouse button 2.
  3. Select Tools - Domino AgentRunner - Run.

The Domino AgentRunner will run your agent using the AgentContext document that you created in Notes. 

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 ToDoAgent class file in the Workbench.  In the Source window, change what the class extends from lotus.notes.DebugAgentBase to lotus.notes.AgentBase. Click your ToDoAgent 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 ToDoAgent.class file.

Running the Agent
You now have an agent that will check your To Do list for any tasks that are due today.

To test the agent, create a task and set the due date as today's date. Create another task with some other day as the due date. You can even assign tasks to other people.  When the agent runs manually or at the time you specified, the owner of the task will receive a mail reminder that the task is due that day.