API
@-Formulas
JavaScript
LotusScript
Reg Exp
Web Design
Notes Client
XPages
 
Send A View To Another User (Part 1)
Recently an end user of ours created a private view that another end user wanted. These end users wanted to know if there was a way to "send a view" from one user to another. Our administrator told the user to get on the phone and describe the design of their view while the other user created their private view. Is there a better way?
Please note... if you have purchased the Reusable Object Library Level 2 application, you can use the "Find New Reusable Objects" feature to quickly download this design element and it's associated documentation at no cost.
In Notes 6, you could switch a view from private to public so it could then be copied/pasted and switched back to private. But that would assume both users have designer access to the database. A better way is using the NotesDXL classes available in Notes 6. In part 1 of this tip, we'll show you how to choose a view in the current database and export it to a DXL file. In part 2, we'll show you how to take that DXL file and import it into a new database.

This processing is handled through agents. Right now the agents assume the current database (so the agent needs to be in the "view to be copied" database). It wouldn't be that difficult to modify the agent so it's in a centralized place and the user chooses the source database.

This agent works by getting all the views in the source (current) database and prompting the user for the view name to "copy". That view is found and then that view (and only that view) is exported in DXL format to a file on the user's machine. The DXL file is placed in the user's Notes data directory in a file called <filename>.dxl where "filename" is the file name of the source database (everything except the .NSF or .NTF at the end).

Here's the code:

Sub Initialize
   Dim session As New NotesSession
   Dim ws As New NotesUIWorkspace
   Dim db As NotesDatabase
   Dim viewNames() As String
   Dim i As Integer
   Dim viewToExport As String
   Dim nc As NotesNoteCollection
   Dim view As NotesView
   Dim fileName As String
   Dim stream As NotesStream
   Dim exporter As NotesDXLExporter
   
   Set db = session.CurrentDatabase
   Redim viewNames(0)
   i = 0
   Forall indView In db.Views
      Redim Preserve viewNames(i)
      viewNames(i) = indView.Name
      i = i+1
   End Forall
   viewToExport = ws.Prompt(4, "Choose View", "Choose the view to export from the list below:", "", viewNames)
   If viewToExport = "" Then Exit Sub
   Set view = db.GetView(viewToExport)
   Set nc = db.CreateNoteCollection(False)
   Call nc.BuildCollection
   Call nc.Add(view)
   fileName = session.GetEnvironmentString("Directory", True)
   If Right(fileName, 1) <> "\" Then fileName = fileName & "\"
   fileName = fileName & Left(db.FileName, Len(db.FileName) - 3) & "dxl"
   Set stream = session.CreateStream
   If Not stream.Open(fileName) Then Exit Sub
   Call stream.Truncate
   Set exporter = session.CreateDXLExporter(nc, stream)
   Call exporter.Process
End Sub

A couple of items need further explanation. The db.CreateNoteCollection(False) statement will create a NotesNoteCollection object. A NotesNoteCollection is similar to a document collection that you're used to, but it can contain design elements in addition to documents. The False parameter says that the collection should initially have nothing in it. You can specify all design elements, or just agents, or just forms, or whatever. Then the Add method adds a specific design element. The parameter can be one of several things including a NotesView object (like the example does) or the Note ID of a design element. You could also add individual documents to the collection.

To export the collection to a file on the file system, you must use a NotesStream object pointing to the file on the file system, so that is used. NotesStream has lots of uses in Notes 6, but DXL is one of the main uses. The Process method on the NotesDXLExporter object populates the file on the file system. Next week we'll take a look at importing the file into another database. The thought is that you take the DXL file that was created through this agent, email it to the user who wants the view, and then they detach the file to their Notes data directory and run the Import agent we'll go over next week.