One of the things that can really slow down your NotesAgents is opening large NotesViews. When coding an agent, it is important to always check if the agent redundantly opens the same NotesView and if access time could be reduced. I do this with a short but handy function that I want to share here:
%REM
Accesses a view and stores it in listView; only opens the view, if the view does not already exist in listView
Input:
- viewname: name of view to be accessed
- listView: list of NotesViews, can be uninitialized
- isRefresh: if true, refreshes the view, otherwise not
Output:
- v: NotesView
- listView: list of NotesViews, returns at least the one accessed
%END REM
Function getView(v As NotesView, viewname As String, listView List As NotesView, isRefresh As Boolean) As Boolean
On Error Goto errorhandler
Set v = Nothing
Dim s As New NotesSession
Dim db As NotesDatabase
Set db = s.CurrentDatabase
If Iselement(listView(viewname)) Then
Set v = listView(viewname)
End If
If v Is Nothing Then
Set v = db.GetView(viewname)
End If
If v Is Nothing Then
' errorhandling
End If
If isRefresh Then
Call v.Refresh()
End If
Set listView(viewname) = v
getView = True
e:
Exit Function
errorhandler:
' errorhandling
Resume e
End Function
I call this function everytime I want to open a NotesView:
Function foo(listView list as NotesView) as Boolean
...
Dim vContacts as NotesView
If Not getView(vContacts, "vContacts", listView, True) Then Exit Function
...
End Function
The getView()-function checks in the list listView, if the view has already been opened. If so, it returns the view that is already in memory. If not (first access), it opens the view, adds it to listView and then returns the view.
Check the comment for what the parameters of getView() do. Note that the return value of my getView()-function only returns true or false, depending if the function ran into an error or not. I just like to have all my functions like that. The NotesView that I want to access is returned in the first parameter.
I pass listView through all my functions and procedures. This way I only open a view, if I have to.
About the AuthorMarcus Foerster works as Systems Architect for Pentos AG in Munich, Germany. His focus lies on the application side, creating collaboration systems for users, groups and enterprises to get their daily work done. This approach includes integrating complex workflows with intuitive user interfaces, using Lotus Notes/Domino with Adobe Flex and other Web technologies.