Domino Code Fragment

Code Name*
Fetching Docs within a Date Range Dynamically
Date*
10/25/2000
Source (or email address if you prefer)*
rkdravid@yahoo.com
IP address:.202.9.161.61
Description*
There exists a set of documents in a databse. Inorder to retrieve the documents that exists within a given Date Range,the following code will be helpful.(if there is any simple code than this please inform the same)
Type*
LotusScript
Categories*
Date/Time Handling
Implementation:
None (plug and play)
Required Client:
5.0
Server:
(none)
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
Create a form with three date fields as startdate,enddate and daterange(allow multiple values only for daterange).
make sure that the property Display seperate values with comma is selected.
Create a hotspot button and name it Fetch(its upto you).Create an embeded view and select the respective view & the first column in it should be datefield and sorted.

Logic: Get the Startdate & Enddate from the user in startdate & enddate fields. On clicking the fetch hotspot button the dates between the startdate & enddate(inclusive) are exploded and put in the daterange field. Then each date is picked from the daterange field and a document collection is used to fetch the matching documents pertaining to the particular date.

The code has been split up into 2 functions namely fetchInFolder and clearFrmFolder.


fetchInFolder Function: This method gets the documents from the view and puts into the folder for a given date.
parameters: v-view name where the documents available. f- folder name where u want to put the documents. dt-the fetch date as string.


Function fetchInFolder(v As String,f As String,dt As String)
Dim session As New NotesSession
Dim ws As New notesuiworkspace
Dim db As NotesDatabase
Dim view As NotesView
Dim dc As NotesDocumentCollection
Dim uidoc As notesuidocument
Set db = session.CurrentDatabase
'the object view is set to the view v.
Set view = db.GetView(v)
Set uidoc=ws.currentdocument
'dt is passed as string and is converted into date
ss=Cdat(dt)
'the object dc set to get documents from view based on the date ss.
Set dc = view.GetAllDocumentsByKey(ss, False)
'puts the documents in the given folder.
Call dc.PutAllInFolder(f)
Call uidoc.refresh
End Function


clearFrmFolder Function: This method clears the documents from the specified folder.

parameters: f- the name of the folder.

Function clearFrmFolder(f As String)
Dim session As New NotesSession
Dim ws As New notesuiworkspace
Dim db As NotesDatabase
Dim view As NotesView
Dim dc As NotesDocumentCollection
Dim uidoc As notesuidocument
Set db = session.CurrentDatabase
'sets the object view with the folder f.
Set view=db.GetView(f)
'doc is assigned the first document from the view
Set doc=view.GetFirstDocument
Set uidoc=ws.currentdocument
While Not (doc Is Nothing)
'removes the document from the folder
Call doc.removefromfolder(f)
'sets the doc object to the first document after removing
'the existing first document
Set doc=view.getfirstdocument
Wend
Call uidoc.refresh
End Function


Fetch Hotspot Button: This Button is used for fetching the documents from the database for the specified daterange.(daterange field which is having all the dates lies between startdate & enddate(inclusive).
Sub Click(Source As Button)
Dim session As New notessession
Dim db As notesdatabase
Dim ws As New notesuiworkspace
Dim uidoc As notesuidocument
Dim drange as String

Set db=session.currentdatabase
Set uidoc=ws.currentdocument
'drange is assigned the daterange value concatinating with comma(,)
drange=uidoc.fieldgettext("daterange") + ","

Dim res As Integer
Dim dat As String
dat=uidoc.FieldGetText("dateofentry")
'clears the documents from the folder FetchedDocs
res=clearFrmFolder("FetchedDocs")
'while loop will puts the documents in the folder.
While Len(drange) >1
i=Instr(1,drange,",")
s=Mid(drange,1,i-1)
temp=Len(drange)-i-1
If temp <0 Then
temp=1
End If
drange=Right(drange,temp)
'the following line calls the fetchFrmFolder.
res=fetchFrmFolder("dateview","favourite",Cstr(s))
Wend
End Sub

Clear Hotspot Button:This is used for clearing the documents from a folder.

Sub Click(Source As Button)
'call the clearFrmFolder for clearing the documents from the specified folder.
res=clearFrmFolder("FetchedDocs")
End Sub