Home > Domino Tips > Developer > QuickTips > Change views selection criteria on the fly
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

QUICKTIPS

Change views selection criteria on the fly


Graham Frey
08.23.2004
Rating: -4.40- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


View member feedback to this tip.

I was asked to provide a calendar view to users, so they could select on the fly what documents were included in the calendar view, based on a designated category. The problem became more difficult when the designated categories were dynamic (i.e., changeable and able to be added to or deleted from).

To solve this problem, I needed to be able to supply the users a way of changing the views selection criteria on the fly. This ability is limited to only Designer access and above, so how could I give this functionality to the end users?

I used the Notes 6 functionality of assigning an agents "run on behalf of" property. I created two agents. The first was called from an outline entry and requested the user to select the category they wished to limit the calendar view selection to. The second agent was called from the first agent (the one where I assigned the "run on behalf of" property to the username we use to sign all of our databases, and, as a default, has manager access to this database).

Here's the code I used in the agents:

Agent1 (Agent to get Category Name 
and to create the new Selection 
Criteria Formula)

Dim s As New NotesSession
Dim ws As New NotesUIWorkspace
Dim db As NotesDatabase
Dim templateview As NotesView
Dim agent As NotesAgent
Dim selection As Variant
Dim selectFormula As String
Dim channels As Variant
Dim uidb As NotesUIDatabase
Dim doc As NotesDocument
 
Set db = s.CurrentDatabase
Set agent = db.GetAgent("(Open Calendar)")
Set templateview  = db.GetView("Calendar")
Set uidb = ws.CurrentDatabase
Call ws.SetTargetFrame("NotesView")

'Get options for selection in Prompt below.
channels = Evaluate( { "All" : @DbColumn
("" : "NoCache"; "";
"Channel"; 1 ) } )
 
selection = ws.Prompt(4, "Channel Selection", 
"Please choose the required
Channel", "All", channels)

If Not Isempty(selection) Then
'Capture the desired selection formula 
  If selection = "All" Then
   selectformula = {SELECT ( ( Form = 
"SalesPromo" ) | (
Form = "MarketingPromo" ) )}
  Else
   selectformula = {SELECT 
( ( Form = "SalesPromo" ) | (
Form = "MarketingPromo" ) ) & Channel = "}
 & selection & {"}
  End If
  
'If the selection formula is the same as the
 current selection formula, just
open the view.
'If the selection formula is not the same
 as the views current selection
formula, then call 'Agent2 to change the
 selection formula in the view, prior
to opening it.  
If selectformula = templateview.SelectionFormula 
Then
   Call uidb.OpenView("Calendar") 
  Else
'Create a temporary document to store the 
new selection formula, so it can be 
passed to Agent2.
   Set doc = db.CreateDocument
   doc.Form = "Calendar"
   doc.SelectFormula = selection
   Call doc.save (True, False)
   'Run the 'Open Calendar' agent on the 
server and pass the agent the note ID 
of the temporary document storing the 
selection formula.
   Call agent.RunOnServer(doc.NoteID)   
   Call uidb.OpenView("Calendar")  
  End If  
 End If

Agent2 (Agent created to amend the views 
selection criteria).
REM This agent must run on the server 
so that the 'Run on behalf of' property 
is used.

Dim session As New NotesSession
Dim templateview As NotesView
Dim selectFormula As String
Dim selection As Variant
Dim db As NotesDatabase
Dim channels As Variant
Dim agent As NotesAgent
Dim doc As NotesDocument
 
Set db = session.currentdatabase
Set templateview  = db.GetView("Calendar")
Set agent = session.CurrentAgent
'Get the temporary document created to 
store the selection formula
Set doc = db.GetDocumentByID
(agent.ParameterDocID)
 
'Change the selection formual accordingly
 If doc.selectformula( 0 ) = "All" Then
  selectformula = {SELECT ( (Form = 
"SalesPromo") | (Form 
= "MarketingPromo") )}
  templateview.SelectionFormula = 
selectformula
  templateview.Refresh  
 Else
  selectformula = {SELECT ( (Form =
 "SalesPromo") | (Form 
= "MarketingPromo") ) & Channel = "} 
& doc.selectformula(0) & {"}
  templateview.SelectionFormula = 
selectformula
  templateview.Refresh 
 End If
 
'Remove the temporary document that 
stored the selection formula.
 Call doc.Remove(True)


MEMBER FEEDBACK TO THIS TIP

Is this a single user application? Once the view selection formula is changed on the server, won't it be changed for all users of the application and possibly cause issues if more than one person is using the database at a time?

—Brian A.

******************************************

No, this is a multi-user database. I had the same question, but fortunately, the continuous change to the view was accepted by the users. The view is used for reference purposes only and each time it is needed, the code forces them to select the criteria and hence, get the view they want. The view will stay the same on their client until they change views or exit the database, even if someone else uses the database on a different client and selects a different criteria.

If this is not acceptable for others, then I can only suggest you try "private on first use" views and see if the same functionality can be applied to these types of views.

—Graham Frey, tip author

******************************************

Why don't you just use @SetViewInfo?

— Hassan V.

******************************************

In most circumstances you could definitely use the @SetViewInfo function. But, in my case the selection criteria did not end at just one selection. The application needed to be able to provide further categorization based on the previous selections. I could not utilize @SetViewInfo because I needed to know what the previous selections were.

My code was enabling them to categorize the calendar and then drill down to further categories within the previous selections.

—Graham Frey, tip author

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member Graham Frey. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
QuickTips
View hidden fields on Lotus Notes/Domino forms
A bevy of Notes/Domino development tips
How to protect your Lotus Notes application design
Merging views
Stop an agent without shutting down the Amgr task
Collapsing outlines
How to make Notes view icons run code
Find all databases associated with a template
Verifying user's date setting and time zone on local PC
Load design for a single database

Lotus Notes Domino Calendar and Contact Management
Synchronize LinkedIn contacts with Lotus Notes Domino
Setting up Rooms and Resources in Lotus Notes Domino 7
Daylight Saving Time 2007 -- seven helpful tips for Lotus Notes administrators
Top 10 Notes/Domino administration tips of 2006
Top 10 Domino administration tips of 2005
Can blank rows in calendar view be suppressed for readers not specified in reader field?
Besides automating administration, Release 7.0 enhances the client side as well
Automatic deletion of dead mail in mail.box
Make only selected To Dos show up on calendar
Error: 'Invalid or nonexistent document'

Lotus Notes Domino Agents
How the Agent Profiler tool improves Notes/Domino performance
Run or restart Notes/Domino agents via text messages
Calculating results for a column in a Lotus Notes view
Approve Lotus Notes documents using a BlackBerry mobile device
LotusScript agent indexes Lotus Notes/Domino databases
Top 10 Lotus Notes/Domino coding and development tips of 2008
Open documents in Lotus Notes from the Web without a UNID
Fix and update Lotus Notes documents with limited access
Verify scheduled agent status with Domino Extensible Language (DXL)
Top 10 Lotus Notes Domino programming and development tips of 2007

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

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.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts