Allowing users to define view criteria dynamically

This tip describes how to allow users to define view criteria dynamically.

I recently had some users with a need to define date intervals for documents that should appear in a view. Essentially, they wanted to be able to enter two dates, and have only the documents with dates in any one of 5 fields show in the view.

One way was to set up a saved search and have the users edit the dates each time, but they had to edit 2 dates for each of 5 fields every time, and when they searched, the column totals disappeared. Also, all documents were selected, so anything they did happened to all of the documents.

My solution was to use a profile document to allow users to enter the dates in one place, and an agent to get the documents into a collection, then place them into a private on first use folder (so that each user could have their own version of the view).

First, create a profile document with two fields: StartDate and EndDate, as well as any instructions for the user. The profile should enforce proper date format.

Then, create a private on first use folder (not stored in desktop) with the necessary columns and two buttons. Users must have the Create Personal Folders/Views privilege in the ACL for this to work.

Title: Report

Button 1: Set Dates (to allow the user to specify the dates). Code: @Command([EditProfile]; "Report Profile"; @UserName)

Button 2: Run Report (to allow the user to populate the folder). Code: @Command([ToolsRunMacro]; "(Run Report)")

Note: I prefer to put the code in an agent rather than the button so I can modify it even after the user has created their private folder.

Finally, create an agent as follows:

Title: Run Report When should this agent run? Manually from Agent List. Which documents should it act on? Run once (@Commands may be used).

Put the following code in the Initialize event:

 Dim session As New NotesSession
 Dim db As NotesDatabase
 Dim profile As NotesDocument
 Dim startdate As String
 Dim enddate As String
 Dim folder As NotesView
 Dim collection As NotesDocumentCollection
 Dim dateTime As New NotesDateTime("12/01/94")
 Set db = session.CurrentDatabase 
 'Get the dates from the report profile
 Set profile = db.GetProfileDocument("Report Profile", session.UserName)
 If Not( profile Is Nothing) Then
  startdate = profile.StartDate(0)
  enddate = profile.EndDate(0)
  'Establish the folder that will be used for the report
  folderName$ = "Report"
  Set folder = db.GetView( folderName$ )
  Set collection = db.AllDocuments
  'Clear the current folder contents
  Call collection.RemoveAllFromFolder( folderName$ )
  searchFormula$ = {Form = "Form Name" & 
 (Date1 >= @TextToTime("} & startdate & {") & Date1 <= @TextToTime("} & enddate & {") | 
 (Date2 >= @TextToTime("} & startdate & {") & Date2 <= @TextToTime("} & enddate & {") | 
 (Date3 >= @TextToTime("} & startdate & {") & Date3 <= @TextToTime("} & enddate & {") | 
 (Date4 >= @TextToTime("} & startdate & {") & Date4 <= @TextToTime("} & enddate & {") | 
 (Date5 >= @TextToTime("} & startdate & {") & Date5 <= @TextToTime("} & enddate & {"))}
  'Get the documents and put them in the folder  
  Set collection = db.Search(searchFormula$,dateTime,0)   
  Call collection.PutAllInFolder( folderName$ )
  Messagebox "No report profile was found."
 End If

Now the user can open the folder, click on Set Dates, enter the start and end dates and save the profile, then click the Run Report button to put the matching documents in the view.

I hope this is valuable to you. Note that you could theoretically set up any values you like in the profile document, then just include them in the db.Search criteria of the agent.

Dig Deeper on Lotus Notes Domino Administration Tools

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...