Search code examples
lotus-noteslotusscriptlotus

parentView property in NotesDocument class


I have a function which calls another function - the bones are shown below.

When the second function runs and reaches the 'set doc = view.getNextDocument(doc)' line, the parentView property on the completely unrelated NotesDocument, doc1, is also updated, thus breaking the original loop.

Any thoughts?

function getDept(){
 dim doc1 as NotesDocument
 dim view1 as NotesView
 .
 .
 .
 set doc1 = view1.getFirstDocument

 while not(doc1 is nothing)
 .
 .
 .
  call getDeptNumber()
 .
 .
 .
  set doc1 = view1.getNextDocument(doc1)

 }

 function getDeptNumber(){
  dim doc as NotesDocument
  dim view as NotesView
  .
  .
  .
  set doc = view.getFirstDocument

  while not(doc is nothing)
  .
  .
  .
   set doc = view.getNextDocument(doc)

  }

It's driving me nuts!

Thanks

Graeme


Solution

  • It's a little unclear without seeing more code, but I suspect your problem may have to do with caching. If you access the same NotesDocument from different views, the second and subsequent accesses may end up using the same document you already have in memory in another part of your code. Using the view entry collection as shown in the other answer will probably help. Set the view's autoupdate property to False also.

    But I can't help but notice that your code is not very well organized or efficient. It looks like your subroutine (which has no parameters, so I assume is using global variables -- bad idea when you can avoid it) is creating a new View object every time it's called. That's expensive. Also, it seems to be iterating through a view for the purposes of looking up a value, which is inefficient. Use a sorted view and search for the value using the methods of View, instead.

    When you need a view object, I suggest you make a method to fetch it once and store it in a class property so that you don't have to search the database for the view more than once.