NotesNut
NotesNut

Reputation: 49

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

Upvotes: 0

Views: 120

Answers (2)

Andre Guirard
Andre Guirard

Reputation: 720

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.

Upvotes: 1

PoisonedYouth
PoisonedYouth

Reputation: 548

If you run over the view and there are changes on documents (which have got effect on view), the first function maybe will get problems.

You'll better use a collection to run over the documents.

   function getDept(){
     dim doc1 as NotesDocument
     dim view1 as NotesView
     dim collEntries as NotesViewEntryCollection
     dim viewEntry as NotesViewEntry
     .
     .
     .
     set collEntries = view1.getAllEntries()
     set viewEntry = collentries.getFirstEntry

     while not(viewEntry is nothing)
     set doc1 = viewEntry.Document
     .
     .
      call getDeptNumber()
     .
     .
     .
      set viewEntry = collEntries.getNextEntry(viewEntry)

     }
    }

Use the same for your other function. But be careful with deleting documents in collection

Upvotes: 1

Related Questions