Creating custom views in Lotus Notes databases

Get code and instructions to set up a Domino agent that lets users easily create 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 = 
Lookupdb.GetView("AdminViewStatus")
 
 Set NewViews_docs = 
NewViews_LookupView.GetAllDocumentsbyKey("1", False)
 Set NewViews_doc = 
NewViews_docs.GetFirstDocument
 
 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
  Else
   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 = 
s.CurrentDatabase.GetView("Template1_u")
   Elseif Level = "2" Then
    Set viewTemplate = 
s.CurrentDatabase.GetView("Template2_u")
   Elseif Level = "3" Then
    Set viewTemplate = 
s.CurrentDatabase.GetView("Template3_u")
   Elseif Level = "4" Then
    Set viewTemplate = 
s.CurrentDatabase.GetView("Template4_u")
   End If
   
  Elseif Main = "Printed" Then
   formula = "SELECT  
(PCenter = """ & PCenter & """ 
& PrintedBy !=  "" &  ProcessedBy = "") "
   
   If Level = "1" Then
    Set viewTemplate = 
s.CurrentDatabase.GetView("Template1_pr")
   Elseif Level = "2" Then
    Set viewTemplate = 
s.CurrentDatabase.GetView("Template2_pr")
   Elseif Level = "3" Then
    Set viewTemplate = 
s.CurrentDatabase.GetView("Template3_pr")
   Elseif Level = "4" Then
    Set viewTemplate = 
s.CurrentDatabase.GetView("Template4_pr")
   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 = 
NewViews_doc.ViewStatusMessage(0) 
& Chr(10) & "View created " & StatusDate
  Call NewViews_doc.Save(True, False)
  
  Set NewViews_doc = 
NewViews_docs.GetNextDocument(NewViews_doc)
 Next
 
 
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

Dig deeper on Lotus Notes Domino Agents

0 comments

Oldest 

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:

-ADS BY GOOGLE

SearchWinIT

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 ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close