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