Dynamic view

During our work on a web application, we were required to show different documents to the users based on different values of the form's "Status" field. This was achieved by creating as many views as the "Status" field can possess. However, this leads to a large increase in the size of database. In addition, it may have an effect on the performance of application.

To achieve our goal without making so many views, we thought of some dynamic view or dynamic view selection criteria. This way, we only to create two views. Following are the steps to achieve the functionality.

1. Create the view (say,"ViewByStatus") in which we want to show documents dynamically based on the value of the "Status" field. 2. In the view selection formula of "ViewByStatus," we are adding code "& @Text(Status) = @Text(statusDyn)". 3. Create a new view (say,"ViewDyn") with first sorted column (key column) having selection as "Status" field. 4. Create a new hidden field (say "StatusDyn") on the form containing "Status" field. 5. On the buttons or links (there'll be one button/link for each dynamic set of documents in the ViewByStatus) through which we are opening our dynamic view ("ViewByStatus"), modify the code to open the agent (say "DynamicViewSelection") by the following code: "./DynamicViewSelection?openagent&Status=X" where "x" is the status value we are passing to our agent. 6. Name of the agent is "DynamicViewSelection." The code is written and described below.

 Sub Initialize Dim Session As New NotesSession Dim doc,notesdoc As notesdocument Dim db As notesdatabase Dim View As Notesview Dim entrycoll As notesviewentrycollection Dim notesentry As notesviewentry Dim ProfileDoc As NotesDocument Dim coll As notesdocumentcollection Dim i,j As Integer Dim tmp As Variant Dim ID,statusDyn As Integer ' Setting of variables/objects Set db = Session.Currentdatabase Set View=db.getview("ViewDyn") Set doc=session.documentcontext Set ProfileDoc = db.GetProfileDocument("HROnlineParameters") Set entrycoll = View.AllEntries ' Get the value of Query_String in variable "tmp" tmp = doc.QUery_String(0) ' Extract value of status from tmp and set in ID ID = Cint(Right$(tmp,1) ) ' Pick all the documents from the ViewDyn with key value as ID Set coll=View.GetAllDocumentsByKey(ID) ' Pick all the entries from the ViewDyn Set entrycoll=View.AllEntries ' Pick first notes entry from the entry collection, and set doc Set notesentry=entrycoll.getfirstentry Set doc=notesentry.document ' Initialization: Set the value of StatusDyn field on all the documents in entrycoll to null doc.StatusDyn=0 Call doc.save(True,True) For j=2 To entrycoll.count Set notesentry=entrycoll.getnextentry(notesentry) Set doc=notesentry.document doc.StatusDyn=0 Call doc.save(True,True) Next ' Set the value of selected documents in coll to ID Set notesdoc=coll.GetFirstDocument notesdoc.StatusDyn=ID Call notesdoc.save (True,True ) For i=2 To coll.count Set notesdoc=coll.getnextdocument(notesdoc) notesdoc.StatusDyn=ID Call notesdoc.save (True,True ) Next ' Code to open the dynamic view (Workdir is the application directory name, which can be specified from the profile document) Workdir = ProfileDoc.HROnlineDirectory(0) Print "" End Sub

This was first published in June 2001

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.