Tuesday, November 07, 2006

 

Create view with script

This goes into the category of "Should have known, but didn't". Even after working in Notes for almost 10 years, I learn something new almost everyday.(as the saying goes). Have you ever had a business customer ask you to "Export everything in the database." ? That's such a vague request that I must just look at them funny and wonder to myself, "How would I do that without building a view column by tedious column?". I was recently asked this but not to this extreme. They actually wanted to export everything from 3 different forms. These forms contain about 300-400 fields. I slept on this one and wondered if there was a method in Lotuscript to Create a view and all the columns in a view. I figured once I created the view, I could loop through all the items of the document and create columns. After finding the "CreateView" method, I preceded to loop throught the items. At some point, I searched Notes.net and found that I could loop through the form and create the columns from the "Fields" property. Nice! Simple, but very helpful. This is new to R6. I had to create two views because the view has a limit around 280 columns.

Dim s As New NotesSession
Dim db As NotesDatabase
Set db = s.CurrentDatabase
Dim viewURS As NotesView
Dim viewURS1 As NotesView
Dim doc As NotesDocument
Dim form As NotesForm
Dim fname As String
Set form = db.GetForm("URS")
fname = form.Name
Set viewURS = db.CreateView("URS Export", "SELECT Form = 'URS'")
Set viewURS1 = db.CreateView("URS Export 1", "SELECT Form = 'URS'")
Dim col As NotesViewColumn

Forall field In form.Fields
If viewURS.ColumnCount < 200 Then

'Create the column
Set col = viewURS.CreateColumn ( viewURS.ColumnCount + 1, field, field)
Else
Set col = viewURS1.CreateColumn ( viewURS1.ColumnCount + 1, field, field)
End If

End Forall

Comments:
Dude! I wish you had posted this a week earlier. I could have used it. :)
 
Dude! I wish you had posted this a week earlier... I could have used it! :)
 
My apologies. I discovered this last Thursday. At least I'm humble enough to admit I didn't know that this method existed. It's amazing to me for all the reading and research I do, I never came across this one.
Necessity is the father of discovery. The next time you get this request you can proudly proclaim how easy this will be.
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to
Posts [Atom]