Problem solve Get help with specific problems with your technologies, process and projects.

Save time by eliminating db.Search()

Avoid using db.Search, instead change the selection formula of the view using LS and simply get all the documents in the view

Tip:

Avoid using db.Search, instead change the selection formula of the view using LS and simply get all the documents in the view.

I was working on a database that required a lot of HTML reports to be generated. For this I had to use the search method of the database as I wanted a collection of documents that were between a user specified date range and had to match certain other user specified search parameters. My approach was to build the search formula and then do a db.Search to get the document collection. This was taking a long time as the search method searches the entire database and then returns a document collection. I was thinking if I could just dynamically change the selection formula of a view and then I would just have to loop through a smaller subset of documents. I elaborated on a piece of code provided by Dan Velasco of Dominopower.com to come up with this solution.
The following code goes in a Lotus Script agent.

Sub Initialize
 Dim session As New NotesSession
 Dim currDB As NotesDatabase
 Dim view As NotesView
 Dim doc As NotesDocument
 Dim entryColl As NotesViewEntryCollection
 
 Set currDB=session.CurrentDatabase
 Set view=currDB.GetView("vwLineItem") ' This is the view whos selection formula I want to change
 Set doc=currDB.GetDocumentByUNID(view.UniversalID)
' Change the selection formula
 Call doc.ReplaceItemValue("$Formula",|SELECT form="frmLineItem" & @Begins(InvoiceNumber;"A01")|)

' just doing a computewithform for safety sake ..not that i have had a prob without using it.
 Call doc.computewithform(False,False)
 Call doc.save(True,True)
' this just returned all the documents with the new selection formula
 Set entryColl=view.AllEntries
 Print entryColl.Count
End Sub

One thing to note is that once the formula is changed the view only displays the entries in the view. It no longer displays any data. You can do a ctrl + A and select all the documents but you will not be able to see data in the view.

Dig Deeper on Lotus Notes Domino Administration Tools

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close