Lotusscript class not returning public property

I am developing a class that returns a sorted NotesDocument collection, to correct the limitation of the the built-in class. My class seems to work fine when run in the debugger when called from an agent, however the returned object does not contain a valid DocumentCollection.

I am new to developing LS classes and am not sure where to start to figure out why the DocumentCollection object is not available.

The agent call is:

Dim objColl As New SortedCollection(“” , “names.nsf”, “Contacts”)

My class is shown below:

Public Class SortedCollection

Public m_NewColl As NotesDocumentCollection



Sub New(server As String, databasePath As String, viewName As String)

	

	Dim s As New NotesSession

	Dim db As NotesDatabase

	Dim view As NotesView

	

	Set db = s.GetDatabase(server, databasePath)

	Set view = db.GetView(ViewName)

	Set m_NewColl = view.GetAllDocumentsByKey("zzxxzz")

	

	Call loadCollection(server, databasePath, viewName)

	

End Sub



Sub loadCollection(server As String, databasePath As String, viewName As String)

	Dim s As New NotesSession

	Dim db As NotesDatabase

	Dim view As NotesView

	Dim doc As NotesDocument

	

	Set db = s.GetDatabase(server, databasePath)

	Set view = db.GetView(ViewName)

	Set doc = view.GetFirstDocument

	

	Do Until doc Is Nothing

		Call m_NewColl.AddDocument(doc)	

		Set doc = view.GetNextDocument(doc)

	Loop

	

End Sub

End Class

Subject: Scoping issue

Instead of using this signatureSub New(server As String, databasePath As String, viewName As String)

use this instead:

Sub New(database as NotesDatabase, viewName As String)

that way the database object doesn’t go out of scope…

Thomas - IBM

Subject: Lotusscript class not returning public property

Some (all?) LotusScript classes cannot exist outside of their container. For example, a NotesRichtextItem is removed when the associated NotesDocument object can no longer be referenced.

I would have thought that a NotesDocumentColection may be an exception but that doesn’t appear to be the case.

Your class works if you move the container objects outside of the methods, i.e.

Public Class SortedCollection

Public m_NewColl As NotesDocumentCollection

Private s As NotesSession

Private db As NotesDatabase

Private view As NotesView



Sub New(server As String, databasePath As String, viewName As String)

	

	Set s = New NotesSession

	Set db = s.GetDatabase(server, databasePath)

	Set view = db.GetView(ViewName)

	Set m_NewColl = view.GetAllDocumentsByKey("zzxxzz")

	

	Call loadCollection(server, databasePath, viewName)

	

End Sub



Sub loadCollection(server As String, databasePath As String, viewName As String)

	Dim doc As NotesDocument

	

	Set s = New NotesSession

	Set db = s.GetDatabase(server, databasePath)

	Set view = db.GetView(ViewName)

	Set doc = view.GetFirstDocument

	

	Do Until doc Is Nothing

		Call m_NewColl.AddDocument(doc) 

		Set doc = view.GetNextDocument(doc)

	Loop

	

End Sub

End Class

I do not know what the implications are if you then run the loadCollection method against a different database or view than the New method in order to append a second set of documents to the collection. Is the collection gone since the originating container has changed?

How about if you used local variables in the loadCollection method?

Please post your findings if you try this.

REF: Thomas’s post

Looks like the container for the NotesDocumentCollection is the database object. Therefore, you should be able to build up a collection but only from documents in the same database.