+2  A: 
  1. No, view selection formulas cannot contain LotusScript

  2. Not with a view, but you're onto something there. I've done that in the past using folders. Views contain a set of documents that match a view selection formula. Folders, on the other hand, can contain a collection of documents placed there by a user or by code. In the Lotusscript world, you access a folder the same way as a view, using the NotesView class. Then you can call the document's PutInFolder method or a documentcollection's PutAllInFolder method to add documents to that folder.

  3. No. You can programmatically specify the formula used by views, though, via the SelectionFormula property. But that property expects a string written in formula language.

  4. I'm not very familiar with the C API, but my bet is you can only do the same as #3 - specify the formula used as the selection formula. It won't help you select documents based on LotusScript code.

I've been down this road before in a few projects, and the best solution I found was what I suggest in answer #2. That is to say you can clear and then populate a folder programmatically, and then take the user to that folder as the final step in your code. Using that method you are free to use LotusScript to filter the documents and build your "query results" view.

Another less ideal, but functional method you can use is to stamp one item within all the documents with a special value, then filter a view to show only documents with items equal to that special value. For example, you can run a search in LotusScript to build a documentcollection using the db.Search method. Then use the documentcollection.StampAll method to set the "SHOWME" item to "YES". Then your view will just have to be set to show only documents where SHOWME = "YES". Of course, you'll need to remove that SHOWME item from all documents in the database as a first step in this code, so you're starting with a clean slate each time. This method would get increasingly slow the more documents you have, but if you only have a few hundred docs it would work fine.

Hope this helps!

Ken Pespisa
Your (3) is not entirely true -- you can create "user defined formulas" by writing a database driver and using @DbCommand, @DbLookup or @DbColumn (Ben Langhinrichs used that trick with his @Midas toolset). The "database driver" would be a DLL containing C API calls. The problem being that you can't use @DbCommand or @DbLookup in a view selection formula either, but if you have the chops to build the tool, you can give Formula-only "developers" the ability to create apps they couldn't otherwise write. (And, if you know CD records like Ben does, you can do @DbLookup against rich text tables.)
Stan Rogers
Good stuff Stan, thanks.
Ken Pespisa
+1  A: 

Unfortunately, you cannot use Lotuscript in view selection formulas. However, one way we have addressed this in the past is to have your complex formula called in a QuerySave (or WebQuerySave) event on a form, and set a hidden field on all documents to Yes or No. Then, simply use that hidden field in your view selection formula:

SELECT (Form = "Form1" & MyFilterField="Y") 
Ed Schembor