Problem solve Get help with specific problems with your technologies, process and projects.

Best places to use scripts on a general level

My question is in regards to the location of my scripts. I've never been able to find anything that outlines the best places to use script are on a general level, ie., when would I use would a script library vs. using the global form scripts vs. using an agent etc. keeping in mind that performance is always a priority.

There is always more than one school of thought on this, primarily because, when it comes to LotusScript/VB/VBScript/VBA/etc, it's mostly a matter of style vs performance, more than requirements. I'll give you my take on it, though...

For Agents:
For agents, I put most of my variables as Globals, by defining them in the (Declarations) section of the agent. If a variable is to be visible and only used in one subroutine/function, then I define it there. My reasons for this are many, but mostly I do it this way so that:
(1) I don't have to pass the variables around as parameters everywhere I go,
(2) because in the past LotusScript had a memory leak when doing that,
(3) it's easier to Debug when all the variables are listed in one place, and
(4) the downsides (increasing the memory heap, etc) are small compared to the performance increase. The globals are actually accessed as fast and in some cases faster than module-local variables.

Script Libraries:
If a piece of code can be compartmentalized (turned into an object or a function), I always try to put it in a Script Library, if it's going to be used more than once. I usually do this just as I realize I'll need it for another agent/button/event. The downsides are far outweighed by the upside of having to fix the code in only one place. In R6 you can share code segements across Dbs in designer, so it's even better, in my opinion - code libraries...cool.

If code is going to be run from more than one place, I put it in an agent (or a script library) and just call the agent from the button/form event/action. If it's something unique to that particular instance of the button, I put it inside the button/etc directly. I hate having to type something more than once, and I really hate having to fix the same spot of code in more than one place.
The only time I put any code in the Globals part of a form is if it's something that needs to be used by more than one event on the form. An example of this is defining a variable in the Globals on a form so it's scope is global for the whole form - I can see it and use it from many different events. I use these for counters, error trap holders, etc.

Shared Actions:
I like shared actions, but I rarely use them. I get more utility (and backward compatibility) out of putting my actions in a subform, and inserting the subform on any forms that need to share the actions. This, of course, doesn't work for views, and I use shared actions for views. I've run into some issues with cascaded shared actions that are available on R6 not working right on R5 and shared actions not being supported on R4.x, so putting them in subforms makes it simpler for me in a mixed client environment, too. Wherever possible, I usually have the action, whether shared or not, just call a hidden agent to do its work.

Dig Deeper on Domino Resources - Part 2

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials

    Search400.com'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 ...