Manage Learn to apply best practices and optimize your operations.

Techniques for writing agents

This tip provides one developer's basic guidelines for coding agents.


These are some basic guidelines for coding agents. Although each developer is unique in his or her coding standard, I wanted to share my style for coding an agent.

1) Naming Convention: agentName | agt&ltabbreviatedAgentName>

2) Use Option Explicit in the Options section. Make use of shared code from existing script libraries. Most of the times, you have a sendMail() in you script library. So make use of it like this -- use "&ltscriptlibraryname>".

3) In the Declarations section, put the agent task and its functionality in easy English language. For example,

Created on:  18-Jul-2005
By: Sunilkumar Vishwakarma
This agent is an autonomous agent 
that fires daily at a scheduled time.
This agent sends a reminder to every manager 
who did not act upon a request for last 3 days 
instead of waiting for approval.

1) Identify the documents waiting 
approval/completion from a manager
2) Send a mail to each of them as a reminder.

4) Declare global variables in the Declarations section. For example:

Dim db as NotesDatabase
Dim dContext as NotesDocument

5) In the Initialize section, first line should be errorHandler.

On Error Goto errorHandler

'Declare variables

'Set Variables

'Agent's Business Logic

'Freeup Resources

Exit Sub
Call handleError("

Here, handleError is a logger function placed in the script library which you can create yourself that will help in debugging the application errors.

6) Make use of subroutines or functions in the agent's local domain. This will make you code more readable and structured. This will make your life easy when a code change is required in the agent or function.

7) When using arrays, make sure to use the following statement in the lifecycle of the agent: Erase &ltarrayName>

8) Whenever referring an object or variable, test it for not being set to Nothing:

   = SomeFunction()
If Not 
    Is Nothing then
  'Code Follows
End If



Coding standards and error handling can be overused. You must use 'Option Declare' -- not only in agents, but in all LotusScript agents.

I'm not sure about putting AGT in the front of the agent. It is far better to name the design element based on its purpose. This makes life easier for other developers who have to understand what you were trying to do.

It's much better to concentrate on performance limitations, and write your code as efficiently as possible. That way, as your applications grow in size, performance won't suffer.
—Andrew B.

Do you have comments on this tip? Let us know.

This tip was submitted to the tip exchange by member Sunilkumar Vishwakarma. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our bimonthly tip contest and you could win a prize and a spot in our Hall of Fame.

Dig Deeper on Lotus Notes Domino Agents

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...