NotesViewNavigator and Document Collections

Hey folks,

I have a bit of a challenge here. I need to gather a collection from a view using a date range. From that collection, I need to create several other collections, but the real challenge is ensuring that the other collections are the result of the first and that as I step through the original collection, I am grabbing unique records to get the other collections.

For example, I would like to search for all Helpdesk tickets created between two dates. Using this, I would then like to step through this collection, and create additional collections, which should be unique. More specifically, once I have my range, I then would like to grab all High, Medium and Low priority tickets.

Here’s where I am so far:

dim session as NotesSession

dim db as NotesDatabase

Dim view as NotesView

dim nav as NotesViewNavigator

dim entry as NotesEntry

dim doc as NotesDocument

dim vdoc as NotesDocument

set db = session.CurrentDatabase

set doc = session.DocumentContext

Set view = db.GetView(VIEWNAME)

search$ = |[Form] = “Tickets” AND[Closed_Date] >= | & doc.FromDate(0) & | AND [Closed_Date] <= | & doc.ToDate(0)

q = view.FTSearch(search$, 0 )

If q > 0 Then

Set nav = view.CreateViewNav

Set entry = nav.GetFirstDocument

Set vdoc = entry.Document

While Not (vdoc Is Nothing)

currentMonth = Month(vdoc.Closed_Date(0))

search$ = |[Form] = “Ticket” AND [Priority] = “High” & @Text(@Month(Closed_Date) = currentMonth & |

Set highDC = db.FTSearch(search$, 0)

search$ = |[Form] = “Ticket” AND [Priority] = “Medium” & @Text(@Month(Closed_Date) = currentMonth & |

Set MedDC = db.FTSearch(search$, 0)

search$ = |[Form] = “Ticket” AND [Priority] = “Low” & @Text(@Month(Closed_Date) = currentMonth & |

Set lowDC = db.FTSearch(search$, 0)

Set entry = nav.GetNextCategory(entry)

If Not entry Is Nothing Then Set entry = nav.GetNextDocument(entry)

Wend

End if ’ q

Thanks,

Cyg

Subject: NotesViewNavigator and Document Collections

This is more easily done by building separate query strings for each group that you want, ensuring that your query string does the hard work rather than traversing collections in the way you do.

And you should use db.Search rather than db.FTSearch - it’s more efficient - you are not doing a full text search - you are looking for secific values in specific fields.

For example:

ss = {Form = “Ticket” & Priority = “High” & your_date_selection_criteria}

set highDC = db.Search(ss, nothing, 0)

ss = {Form = “Ticket” & Priority = “Medium” & your_date_selection_criteria}

set medDC = db.Search(ss, nothing, 0)

etc . . .

HTH

Cheers

Subject: RE: NotesViewNavigator and Document Collections

Simon,

Thanks for your response. Just one other quick question: what am I missing here?

search$ = {Form = “Ticket” & Priority = “High” & Team = “Testers” & Closed_Date >=| & doc.FromDate( 0 ) & | Closed_Date <=| & doc.ToDate( 0 )}

Set highDC = db.Search(search$, Nothing, 0)

Thanks,

Cyg

Subject: RE: NotesViewNavigator and Document Collections

When you run it in debug mode, is your search$ string showing that it’s picking up the values from doc.FromDate(0) & doc.ToDate(0)? If not, it means you’ve got to do something like:

{Form = "… & Closed_Date >= “} & doc.FromDate(0) & {” & Closed_date <= etc.

Are FromDate & ToDate time/date or text? If they’re text are they using the same date format the Closed_Date will be in?

Check too how your date fields are stored. Not sure if it matters if they’ve got time-stamps on them. You could try using DateOnly on them to get just the date portion.

Searching using dates can often be a trial & error process especially when you combine formula & LS date formats like you’re doing. If nothing else seems to work you may need to convert your doc.FromDate & doc.ToDate fields into date literals in order to include them in the search string.

Subject: RE: NotesViewNavigator and Document Collections

Here’s how I do what you’re trying to do. The problem is the transition between LS dates and @Formula dates. This agent will read a document and select documents based on a field value in the first document. Which is what you’re trying to do.

Sub Initialize

Dim sess As New NotesSession

Dim db As notesdatabase

Dim ndc As NotesDocumentCollection

Dim ss As String



Set db = sess.CurrentDatabase



Dim view As NotesView

Dim doc As NotesDocument



Set view = db.GetView("dates")

Call view.Refresh()



Set doc = view.GetFirstDocument()



Dim dd As String

Dim mm As String

Dim yyyy As String



dd = Day(doc.date1(0))

mm = Month(doc.date1(0))

yyyy = Year(doc.date1(0))



ss = {date1 = @date(} & yyyy & {;} & mm & {;} & dd & {)}



Set ndc = db.Search(ss, Nothing, 0)



Msgbox ndc.Count

End Sub

HTH

Cheers