I am trying to build a very simple agent that checks to see if a field contains a unique value inside the database. It either crashes Notes when I run it & leaves all Lotus apps hung (thank goodness for KillNotes!), or gives a meaningless error (4005, which means NOTES_ERR_ERROR2, whatever that is!).
Here’s the essence of the code, can anyone help me please.
Set nc = db.AllDocuments
Set doc = nc.GetFirstDocument
While Not (doc Is Nothing)
…Set nextdoc = nc.GetNextDocument(doc)
…look4$=Trim$(doc.Hierarchy(0)) ’ the field I’m testing to see if it’s unique
…If look4$<>“” Then
…Set found = db.FTSearch(look4$,0)
…If found.count>1 Then
…'Call doc.Delete - commented this line out for testing
…End If
…End If
…Set doc=nextdoc
Wend
Subject: very simple piece of LS is crashing Notes
It’s probably because you are deleting a document that’s in your document collection, then trying to continue on with the collection. I’ve mistakenly done this before and things really get confused.
A better technique may be create a view that sorts the documents on Hierarchy. Then write an agent that cycles through the view, comparing the current document with the one before (above) it. If the values are the same, set a field in the previous document that will mark it for deletion. After you’ve cycled through the view, go through the documents again deleting the documents that have been marked for deletion.
Subject: very simple piece of LS is crashing Notes
Did you try to process the document collection in reverse order?
Set nc = db.AllDocuments
Set doc = nc.GetLastDocument
While Not (doc Is Nothing)
…Set nextdoc = nc.GetPrevDocument(doc)
(…)
…If found.count>1 Then
…'Call doc.Delete …End If
Anyway, you should better create a view showing all documents, sorted by your “is double entry” criteria.
You can determine if a record is in your view multiple times by walking thru the records. If last recort has same “Key” as current record then the recort is double and you can delete “last record”
Guido
Subject: RE: very simple piece of LS is crashing Notes
Thanks to you all for the suggestions. In the end it’s how I did it, but I’d still like to know how a simple piece of LS can crash the whole system, and it did it even when I had commented out the Delete functions - it was bombing out before it ever got there.
Subject: very simple piece of LS is crashing Notes
You are doing a lot of expensive transactions (db.AllDocuments and the a DB.FTSearch for each document in the collection).
The easiest solution is to create a view containing the documents created by the form in question and have the first column sorted on this field and categorized.
Then you can use the NotesViewNavigator class to do your processing.