Reg Exp
Web Design
Notes Client
Open Database To A Document
There may come a time when you will want to open a database in the Notes client to a particular document. Maybe a settings document for the application.

"This is easy" you say - just put the document link in the About Database document and set the database properties to open that first document link.

This may not always work, however. What if someone makes a copy of the database? If they copy design only, there's no document to link. Even if they copied the design and documents, that document will have a different unique ID (because a copy was made and not a replica) so the link won't work. The method outlined here will work all the time, guaranteed.

First, create a view that will hold the document to open. If you want to open a profile document, this step can be omitted. Basically, you need some unique way to identify the document to be opened. In this example, there is a view that selects the one document to be opened. So the only document in that view is the "home page" for the application in the Notes client.

Next, create a Page design element. Call it something like "Home - Page". There doesn't need to be any content, but put the following script in the PostOpen event for the page:

   Dim s As New NotesSession
   Dim ws As New NotesUIWorkspace
   Dim db As NotesDatabase
   Dim view As NotesView
   Dim doc As NotesDocument
   Set db = s.currentDatabase
   Set view = db.getView("vwLookupDbProfile")
   Set doc = view.getFirstDocument
   If doc Is Nothing Then
      Set doc = db.createDocument()
      Call doc.replaceItemValue("Form", "DbProfile")
   End If
   Call Source.Close() ' Close the current page
   Call ws.editDocument(True, doc)

The code finds that lookup view, then sees if there is a document in the view. If not, one is created and the form is set. At this point, either the existing document has been found or one has been created. Either way, there's a handle to a document in the doc variable. Open that document in edit mode and close the page design element.

Now, it's just a matter of opening that page. Unfortunately, there isn't the option to open a page in the Notes client like there is in a browser. But this is easy to fix. Simply create a frameset, called something like "Home - Frameset" that has only one frame in it. The source for that frame is your page you just created.

Now, whenever that database is opened, the settings profile will either be created and opened (if it doesn't exist) or the existing profile will be opened.

Note: if you want to use a true profile document instead, you won't need the view reference in the LotusScript code - just get a handle to the profile document. If the profile doesn't exist, Notes will create it for you, so you won't need to check to create the profile. So the above code would be much shorter.