Creating custom views in Lotus Notes databases

Related information from SearchDomino.com:
Further improve your Domino views on the Web

Creating dynamic categorized views

Editing fields in a Lotus Notes view with Ajax

Creating a Lotus Notes view column categorized by month

Lotus Notes Domino Agents Reference Center

This tip will allow users to easily create custom views in Lotus Notes databases. To accomplish this, the user fills out a view creation document that acts as the instructions for the new view. An agent then runs overnight and generates the new view based on a view template.

Here is the code:

 Sub Initialize
 Dim s As New NotesSession
 Dim viewTemplate As NotesView
 Dim NewView As NotesView
 Dim db As NotesDatabase
 Dim col1 As NotesViewColumn
 Dim col2 As NotesViewColumn
 Dim formula As String
 Set db = s.CurrentDatabase  
 server = db.Server     
 filepath = db.FilePath

 Set Lookupdb = s.GetDatabase(server,filepath)
 Set NewViews_LookupView = 
 Set NewViews_docs = 
NewViews_LookupView.GetAllDocumentsbyKey("1", False)
 Set NewViews_doc = 
 For a = 1 To NewViews_docs.Count

"View hierarchy"
 in this example, all views have 3-4 levels of hierarchy
  Main = NewViews_doc.MainFolder(0)
  Sub1 = NewViews_doc.SubFolder1(0)
  Sub2 = NewViews_doc.SubFolder2(0)
  Sub3 = NewViews_doc.SubFolder3(0)
  If Sub3 = "" Then
   NewViewName = Main + "" + Sub1 + "" + Sub2
   NewViewName = Main + "" + Sub1 + "" + Sub2 + "" + Sub3
  End If
  NewViewAlias = NewViews_doc.ViewAlias(0)
  PCenter = NewViews_doc.PCenter(0)
  Level = NewViews_doc.ProcessingLevel(0)
  ViewDatabase = NewViews_doc.Database(0)
"Determine which view 
template to use" 
in this example there are 8 pre-set templates  
  If Main = "Unprocessed" Then
   formula = "SELECT  (PCenter = """ & 
PCenter & """ & PrintedBy =  "" &  ProcessedBy = "") "
   If Level = "1" Then
    Set viewTemplate = 
   Elseif Level = "2" Then
    Set viewTemplate = 
   Elseif Level = "3" Then
    Set viewTemplate = 
   Elseif Level = "4" Then
    Set viewTemplate = 
   End If
  Elseif Main = "Printed" Then
   formula = "SELECT  
(PCenter = """ & PCenter & """ 
& PrintedBy !=  "" &  ProcessedBy = "") "
   If Level = "1" Then
    Set viewTemplate = 
   Elseif Level = "2" Then
    Set viewTemplate = 
   Elseif Level = "3" Then
    Set viewTemplate = 
   Elseif Level = "4" Then
    Set viewTemplate = 
   End If
  End If
'---Create the view based on the template
   Set NewView = s.CurrentDatabase.
CreateView(NewViewName, formula, viewTemplate)
   NewView.Aliases = NewViewAlias

'---Set View Creation Documents status
  'Set NewView = s.CurrentDatabase.
CreateView(NewViewName, "SELECT @All")
  StatusDate = Format(Now(),"mm/dd/yyyy hh:mm ampm")
  NewViews_doc.ViewStatus = "2"
  NewViews_doc.ViewStatusMessage = 
& Chr(10) & "View created " & StatusDate
  Call NewViews_doc.Save(True, False)
  Set NewViews_doc = 
End Sub

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip library by member Amy Crisanti. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

This was first published in August 2007

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.