Date Range generated 'view'

I have a form that contains two date fields, a hidden field, a button and a table. The user enters in the start and end date that is used to pull in all documents within that date range into a table (acting as a view) to show the user. (The hidden field pulls in the date range and explodes all the dates) Now, this is a notes version and I would like to get it working as I’m going to web enable it. However, for some reason its not matching any documents when it should. I ran my code below through the debugger and the dc.Count always = 0 when it should’ve found a match.

Sub Click(Source As Button)

Dim counter As Integer

Dim allDates As Variant

Dim concatResults As String

Dim dc As notesdocumentcollection

Dim session As New NotesSession

Dim db As NotesDatabase

Dim lookupView As NotesView

Dim currDoc As NotesDocument

Dim doc As NotesDocument 

Dim uidoc As NotesUIDocument

Set db = session.CurrentDatabase

Set lookupView = db.GetView( "ABCD" )

counter = 0



Dim ws As New NotesUIWorkspace

Set uidoc = ws.CurrentDocument



If ( uidoc.FieldGetText("FieldToSearch")= "" ) Then

	Msgbox "Please select a field to search on.",MB_ICONSTOP, "Firewall Query"

	Exit Sub

Elseif ( (uidoc.FieldGetText("StartDate")= "" ) Or (uidoc.FieldGetText("EndDate") = "" ) )Then

	Msgbox "Please enter a Start and End Date before you do your query.",MB_ICONSTOP, "Firewall Query"

	Exit Sub

End If



If uidoc.FieldGetText("FieldToSearch") = "Completed Date" Then

	Set lookupView = db.GetView( "ABCD" )

Else

	Set lookupView = db.GetView( "ABSD" )

End If



Set currdoc = uidoc.Document

Call uidoc.Refresh

allDates = currdoc.GetItemValue("DatesExploded")



Forall v In allDates

	Set dc = lookupView.GetAllDocumentsByKey(v,True)

	If Not dc.Count = 0 Then

		Set doc = dc.GetFirstDocument

		While Not doc Is Nothing

			counter = counter + 1

			If uidoc.FieldGetText("FieldToSearch") = "Completed Date" Then

				Set dTime = New NotesDateTime(Cstr(doc.CompletedDate(0)) )

				concatResults = Cstr(dTime.DateOnly) & Chr(9) & Chr(9) & Cstr(doc.RequestNum(0)) & Chr(9) & Chr(9) & Cstr(doc.NameOfService(0))

			Else

				Set dTime = New NotesDateTime(Cstr(doc.ScheduledDate(0)) )

				concatResults = Cstr(dTime.DateOnly) & Chr(9) & Chr(9) & Cstr(doc.RequestNum(0)) & Chr(9) & Chr(9) & Cstr(doc.NameOfService(0))

			End If

			Call uidoc.FieldAppendText("dResults",";" & concatResults)

			Set doc = dc.GetNextDocument(doc)

		Wend

	End If

End Forall



If counter = 0 Then

	Messagebox("No results were found for your search criteria.")

End If



Call uidoc.Refresh

End Sub

Anybody have any ideas as to why the GetAllDocumentsByKey method isn’t working? Its not matching any documents from the “DatesExploded” hidden field, when it should.

Subject: RE: Date Range generated ‘view’

The lookup isn’t working, probably because the datatype of the keys in the column (date?) are not the same as the datatype of the key value you’re supplying (string?), or because the view isn’t sorted by that column.

However, there are better ways to do this. Doing a lookup for each date in a range is slow… A full-text search could return all these documents at once; or you could binary-search among the view entries to find the first and last row entries that are in your range.

Subject: Date Range generated ‘view’

Have you look at the Notes DateRange class? There are some good examples in the Designer Help.

Subject: RE: Date Range generated ‘view’

Thanks for your advice. I’ll look into those.

I think I maybe have figured it out to work on Notes, however, I’m unfamilar with using LotusScript on the web. I put this code in an agent…but of course it doesn’t work like it does on Notes. I click the button that refers to the agent with this code and for some reason it loads another black web page.

Any ideas? I’ve only used LotusScript on the web for email notifications. Nothing like this…

Is it possible to use?

Subject: RE: Date Range generated ‘view’

If the code below is what you have placed into the agent, it will not work. The reason is that you cannot use UI objects on the web (they are for the Notes client only… web browsers don’t know what they are). To get the currently open document in a web browser look at the NotesSession.documentContext property. This returns a NotesDocument object. You would then use back-end methods to access your fields. Also, messageboxes do not work on the web. You will need to write your messages out by generating Javascript alerts and then using history.go(-1) … check the history part with other members of the forum, I don’t really use this method all that much anymore. Ideally, I would do the checks using javascript on the form before it is submitted. Only if all your validation tests pass, would you submit the form. This makes all of your code cleaner. The javascript validation function is called onSubmit() and then your server processing is done in the agent.

Dim counter As Integer

Dim allDates As Variant

Dim concatResults As String

Dim dc As notesdocumentcollection

Dim session As New NotesSession

Dim db As NotesDatabase

Dim lookupView As NotesView

Dim currDoc As NotesDocument

Dim doc As NotesDocument

Dim uidoc As NotesUIDocument

Set db = session.CurrentDatabase

Set lookupView = db.GetView( “ABCD” )

counter = 0

Dim s as New NotesSession

dim currdoc as NotesDocument

set doc = s.DocumentContext

If doc.FieldToSearch(0) = “Completed Date” Then

Set lookupView = db.GetView( “ABCD” )

Else

Set lookupView = db.GetView( “ABSD” )

End If

'Why was the uidocument refreshed here? Not a problem, but it may not be needed if nothing was actually occurring. It won’t work in a WQS agent because you cannot use uidoc

allDates = currdoc.GetItemValue(“DatesExploded”)

Forall v In allDates

Set dc = lookupView.GetAllDocumentsByKey(v,True)

If Not dc.Count = 0 Then

Set doc = dc.GetFirstDocument

While Not doc Is Nothing

counter = counter + 1

If currdoc.FieldToSearch(0) = “Completed Date” Then

Set dTime = New NotesDateTime(Cstr(doc.CompletedDate(0)) )

concatResults = Cstr(dTime.DateOnly) & Chr(9) & Chr(9) & Cstr(doc.RequestNum(0)) & Chr(9) & Chr(9) & Cstr(doc.NameOfService(0))

Else

Set dTime = New NotesDateTime(Cstr(doc.ScheduledDate(0)) )

concatResults = Cstr(dTime.DateOnly) & Chr(9) & Chr(9) & Cstr(doc.RequestNum(0)) & Chr(9) & Chr(9) & Cstr(doc.NameOfService(0))

End If

currdoc.dResults = currdoc.dResults + “;” + concatResults

Set doc = dc.GetNextDocument(doc)

Wend

End If

End Forall

If counter = 0 Then

'Messagebox(“No results were found for your search criteria.”)

'Use LotusScript to build a window.alert in Javascript here or Write the message out using Javascript document.write. You can then add a link to go back (or you can make it part of the Javascript)

End If

'Note that I have not actually tested the changes to your code that I listed above. Once you can successfully submit the form and get the WQS agent to run correctly from the browser… you can then add the code to handle what happens AFTER the submit (re-open the document in read-mode… display a message page… navigate to a URL… open a view… etc.)

There is a section on Web Agents in the Designer help. It tells you how you can run them and things you can and can’t do with them.