Thursday, April 06, 2006

Show-n-Tell Thursday - updating folder design

Folders can be a really useful design element. The only problem is that if you allow users to create shared folders in a production database, they don't inherit design changes from the template's default folder. Here's a fairly simple way to selectively update the design of those folders, or even allow an end user to update the design (after a developer has made changes and refreshed the design of the default folder from the template.)

Create a form that contains two visible dialog list fields, folderChoices and templateFolder. Also create a hidden field called folderList and a SaveOptions field set to "0". The default value of folderList should be @Unique(folderList). folderChoices should be set up to use formula for choices, and the formula should just be the field name folderList. The default value of templateFolder could go two ways: if you have only one folder template, make the field a text field instead, and set the default value to the name of the template folder. If, as we do, you have more than one folder design that can be used as a template, leave the field as a dialog list using formula for choices, and set the default value to folderList : "(Default Folder)" where the appended value is the name of your default folder (hidden in our case.)

Add this code to your PostOpen event:


Sub Postopen(Source As Notesuidocument)
Dim s As New notessession
Dim db As notesdatabase
Dim fList As NotesItem
Dim doc As notesdocument

Set db = s.CurrentDatabase
Set doc = Source.Document
Set fList = doc.GetFirstItem("folderList")
Forall v In db.Views
If v.isfolder And v.name <> "Default Folder" And v.name <> "(Default Folder)" And Not fList.Contains(v.name) Then
Call fList.AppendToTextList(v.name)
End If
End Forall
End Sub


Create a button and put this code behind it:


Sub Click(Source As Button)
On Error Goto errhand

Dim w As New notesuiworkspace
Dim db As NotesDatabase
Dim folderTemplate As String
Dim doc As notesdocument
Dim fName As String

Set db = w.currentdatabase.database
Set doc = w.currentdocument.document
folderTemplate = doc.templateFolder(0)

Forall x In doc.folderChoices
fName = Replace(x, "\" , "\\") Evaluate(|@UpdateViewDesign("|& fName & |";"| & folderTemplate & |")|)
End Forall
Msgbox "Update complete"
Exit Sub
errhand:
Msgbox "error at line " & Erl & ": " & Error
Exit Sub
End Sub


Add a button or outline entry in your database navigation that creates a new document using this form. The user can then choose which folders to update, and which folder to use as the design template.

LotusScript was converted to HTML using the ls2html routine,
provided by Julian Robichaux at nsftools.com.


Show-n-Tell Thursday

No comments: