Allowing 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.

This was first published in August 2002

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.