Home > Domino Tips > Developer > Agent > Techniques for writing agents
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

AGENT

Techniques for writing agents


Sunilkumar Vishwakarma
07.18.2005
Rating: -3.25- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


VIEW MEMBER FEEDACK TO THIS TIP

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<abbreviatedAgentName>

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 "<scriptlibraryname>".

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

%REM
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.

Logic:
--------
1) Identify the documents waiting 
approval/completion from a manager
2) Send a mail to each of them as a reminder.
%END REM

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
errorHandler:
Call handleError("",Err,Error$,Erl)  
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 <arrayName>

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

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

MEMBER FEEDBACK TO THIS TIP

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 SearchDomino.com 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.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Agent
Run or restart Notes/Domino agents via text messages
Approve Lotus Notes documents using a BlackBerry mobile device
LotusScript agent indexes Lotus Notes/Domino databases
Open documents in Lotus Notes from the Web without a UNID
Fix and update Lotus Notes documents with limited access
Verify scheduled agent status with Domino Extensible Language (DXL)
How to export data from a Lotus Notes database to a CSV file
Enable or disable scheduled agents without opening the Lotus Notes database design
Creating custom views in Lotus Notes databases
Editing fields in a Lotus Notes view with Ajax

Lotus Notes Domino Agents
How the Agent Profiler tool improves Notes/Domino performance
Run or restart Notes/Domino agents via text messages
Calculating results for a column in a Lotus Notes view
Approve Lotus Notes documents using a BlackBerry mobile device
LotusScript agent indexes Lotus Notes/Domino databases
Top 10 Lotus Notes/Domino coding and development tips of 2008
Open documents in Lotus Notes from the Web without a UNID
Fix and update Lotus Notes documents with limited access
Verify scheduled agent status with Domino Extensible Language (DXL)
Top 10 Lotus Notes Domino programming and development tips of 2007

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts