Reg Exp
Web Design
Notes Client
Quickly Collect All Documents
I'm sure you've developed applications where it was important to know how many documents meeting a certain criteria there were in the database. There are multiple ways of doing this, but here we'll point out one you might not have thought of. It makes use of Notes built-in ability to handle view indexes with efficiency.

What you will want to do is design a new view. The selection formula for the view will bring in all the documents you would want to count. You can use an existing view if you would like, as long as the view isn't being used for other look-ups. The first column in the view should be 1 character wide, cannot be resized, is sorted in ascending order, and have no header. (This way users won't really be able to tell that there's an extra column; that's why you can use an existing view). The value for the column should be a constant string value "     x" (that's 5 spaces followed by the letter x). The actual value doesn't matter, as long as you know what it is. The spaces at the start are so nothing will appear in that fixed 1 character width in the column. And since the column can't be resized, users will never know something is there.

In your agent that wants to find out how many documents meet that criteria, get a handle to the view and then grab a collection of documents meeting that constant criteria, as in:

   Set view = db.GetView("My View")
   Set coll = view.GetAllDocumentsByKey("     x", True)

At this point, coll.Count will tell you how many documents are in that view. This works because the GetAllDocumentsByKey method goes against the first sorted column in the view. Since the column we added was sorted and the first column in the view, that will be the column used. Since all the values in the column are the same and that's the key we look for, all the documents in the view will be retrieved.

Another use of this technique would be to update all the documents meeting a certain criteria. For example, there might be a nightly process that counts how many documents have been created that day. The form could have a computed field that sets a value. The view would select documents with that value. The agent would grab all the documents in the view, report how many there are, then use the StampAll method from the NotesDocumentCollection object to remove them all from the view.