Reference from
http://www.ibm.com/developerworks/lotus/library/ls-LS_views/index.html
Example 1: Programming the view selection formula
Changing the view selection formula is a particularly useful example of giving users control that helps them to focus on information. In the LSViews database, a view named All presents an HR application: The documents list employees who are leaving a company, together with their department and last date of employment. The view displays several shared actions in its action bar. All of these actions execute agents stored in the application. (The reason for making them agents rather than actions is that actions cannot be run on behalf of.) One of these agents, Date Range, allows the database user to enter beginning and ending dates and to reset the selection formula for the view to display only documents that fall within that date range. The advantage of this agent over a generic full-text search is that the view's structure remains the same. The view display maintains category headings and the order of the documents in the view, both of which would be lost in a search.
The Date Range action uses an @Command formula to run an agent named Dates: @Command([RunToolsMacro];"(Dates)"). (The name of the agent appears in parentheses because it is hidden from the agent menu.) The agent prompts the user to enter starting and ending dates, then creates a selection formula from the values the user enters:
Sub Initialize
'Prompts user for beginning and ending dates
'Changes selection formula to display docs between dates
Dim uiw As New NotesUIWorkspace
Dim uiview As NotesUIView
Dim view As NotesView
Dim formula As String
Dim one As String
Dim two As String
Dim ct As Integer
one = uiw.Prompt(Prompt_OKCANCELEDIT,"Enter the starting date",
"Start Date (use format MM/DD/YY)","")
two = uiw.Prompt(Prompt_OKCANCELEDIT,"Enter the ending date",
"End Date (use format MM/DD/YY)","")
formula = |SELECT Date > [| & one & |]
& Date < [| & two & |]|
Set uiview = uiw.CurrentView
Set view = uiview.View
view.SelectionFormula = formula
Call uiw.ViewRebuild
ct = view.EntryCount
Messagebox "The number of docs in this view = " &
ct,,"Count of docs in view"
End Sub
http://www-01.ibm.com/support/docview.wss?rs=463&context=SSKTMJ&context=SSKTWP&q1=@today+view+selection&uid=swg27003557&loc=en_US&cs=utf-8&lang=en
สืบเนื่องจากบทความ Programming the view selection formula ของ ibm และจากบทความอีกอันที่พูดถึงเรื่อง performance ของการใช้ date เป็นเงื่อนไขในวิวซึ่งให้ผลลัพท์ที่ช้าที่สุดในการ update index ของวิวตามด้านล่างนี้
อันนี้ผมเห็นสิ่งที่ต่างจาก code ที่คุณ sakdit เขียนคือการกำหนดช่วงของวันที่โดยใช้สูตรเป็น @Today แต่ของที่ ibm แนะนำจะเป็นการส่งค่าของวันเข้าไปเลยแทนการใช้ @Today
|SELECT Date > [| & one & |]
& Date < [| & two & |]|
อันนี้ผมยังไม่ได้ลองนะครับ แต่ที่แน่ ๆ คือการใช้ @Today กับ @Now นี่มีผลกับความช้าหรือเร็วในการ rebuild index ในวิวแน่ ๆ ครับ ยังไงลองปรับ code ดูก่อนนะครับเผื่อจะช่วยได้ ถ้ายังไม่หายคงต้อง report ไปยัง support ของทาง ibm ให้แก้ปัญหานี้ใน release ถัด ๆ ไปแล้วหล่ะครับ |