I was recently asked by a customer to create a script to do the following:
1. User selects a document from a view and clicks an action button.
2. The script uses the CustID field in the highlighted document to locate all docs with this matching CustID.
3. Display all documents with this CustID in a view.
I used the following method to create a dynamic view. First, I created a view for displaying the document collection. I categorized this view by CustID field. I then created a form called "Results" with the categorized view embedded within. When you embed a view in a form or page, you can specify that only one category will be shown. The formula that I used to select which category to show is as follows:
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
Next, I created an action in the primary view with the following LotusScript:
Sub Click(Source As Button)
Dim ws As New notesuiworkspace
Dim db As notesdatabase
Dim session As New notessession
Set db = session.currentdatabase 'Obtain a handle on the selected document in the view Dim dc As notesdocumentcollection
Set dc = db.unprocesseddocuments
Dim doc As notesdocument
Set doc = dc.getfirstdocument
If doc Is Nothing Then
Msgbox "Please select a document"
End If 'Set an environment variable to the CustID of the selected document Call session.SetEnvironmentVar( "CustID", doc.CustID(0)) 'Create a new document using the "Results" form and open the uidocument Dim ndoc As notesdocument
Set ndoc = db.createdocument
ndoc.form = "Results"
Dim uidoc As notesuidocument
Set uidoc = ws.EditDocument(False, ndoc ) End Sub