Using CreateViewNavFromCategory not working

Can someone tell me what’s wrong with this code? I have view based on dates and am trying to determine the work schedule for a particular week but it’s not finding the view entries.

There are entries are there… says entry is nothing

Dim memo As NotesDocument



Set memo = New NotesDocument(db)

Call dbug.LogAction("memo is set")

’ memo.Subject = "Schedule for the week of " & Cstr(Date)

memo.Principal=db.Title



Set rtitem = New notesrichtextitem(memo, "Body")

Call dbug.LogAction("set new rtitem")



Set object = rtitem.EmbedObject ( EMBED_ATTACHMENT, "", fileName$, "Filler" )

Call dbug.LogAction("set object")



Set searchView = db.GetView("DAYSOUTNEXTWEEK")

Call dbug.LogAction("search is set")



Dim StartDate As New NotesDateTime(Date)

Dim wd As Integer



wd%=Weekday(StartDate.DateOnly)

Call StartDate.AdjustDay(2-wd)

Stop



Dim EndDate As New NotesDateTime(StartDate.DateOnly)

Call EndDate.AdjustDay(4)



Dim columnValue1 As Variant

Dim columnValue2 As Variant

Dim xdate As Variant

Dim modifiedDateTime As NotesDateTime



Dim entryDoc As notesviewentry



memo.Subject = "Schedule for the week of " & Cstr(StartDate.DateOnly) & " - " & Cstr(EndDate.DateOnly)

Call dbug.LogAction(" week of " & Cstr(StartDate.DateOnly) & " - " & Cstr(EndDate.DateOnly))



Call rtitem.AddNewline(1)		

Call rtitem.AppendText("The following associates will not be here the week of " & Cstr(StartDate.DateOnly) & " - " & Cstr(EndDate.DateOnly))



For i=0 To 4

	Call StartDate.AdjustDay(i)

	

	Set nav=searchView.CreateViewNavFromCategory(StartDate.DateOnly)

	Call dbug.LogAction("viewnav is set")

	Call rtitem.AddNewline(1)

	

	

	Set entry = nav.GetFirst

	

	If entry Is Nothing Then 

		Call rtitem.AddNewline(1)

		Print "everyone is here"

		Call dbug.LogAction(Cstr(StartDate.DateOnly) & ": everyone is here")	

		Call rtitem.AppendText(Cstr(StartDate.DateOnly))

		Call rtitem.AddNewline(1)

		Call rtitem.AppendText("There are no scheduled attendance records for this day.")

	Else		

		

		Call rtitem.AddNewline(2)				

		

		If entry.ChildCount >0 Then 

			If entry.IsCategory Then			'

				Call rtitem.AddNewline(1)

				columnValue1 = entry.ColumnValues(0)

				

				If Isarray(columnValue1) Then

					Print "entry.ColumnValues ="& Implode(columnValue1, ",")

					xdate= Implode(columnValue1, ",")

				Else 

					Print "entry.ColumnValues ="& columnValue1

					xdate=columnValue1					

				End If

				

				

				Call rtitem.AppendText(xdate)

				Call rtitem.AddNewline(1)

				

				Set entryDoc=nav.GetChild(entry)

				

				While Not entryDoc Is Nothing

					columnValue2 = entryDoc.ColumnValues(1)

					Call rtitem.AddTab(1)

					

					If Isarray(columnValue2) Then							

						Print "entryDoc.ColumnValues ="& Implode(columnValue2, ",")

						Call rtitem.AppendText(Implode(columnValue2, ","))

					Else 

						Print "entryDoc.ColumnValues ="& columnValue2

						Call rtitem.AppendText(columnValue2)

					End If

					

					Call rtitem.AddNewline(1)			

					Set entryDoc=nav.GetNextSibling(entryDoc)

				Wend

				

			End If

			

		End If 

		

	End If 

	

Next

sendMail:

Subject: using CreateViewNavFromCategory not working

I believe it’s a datatype issue. DateOnly returns a string; your view is probably sorted by date/time values, not by text values. The doc for CreateViewNavFromCategory expects its argument to be a string, so there may be no way to use it in a view that’s categorized by non-text values.

Is there a reason you can’t use NotesView.GetAllEntriesByKey instead? (I’m not sure whether the results will be in view order.)

Subject: RE: using CreateViewNavFromCategory not working

I get nothing with Cstr(StartDate.DateOnly) or StartDate.DateOnly:

For i=1 To 5

	

	Set vc=searchView.GetAllEntriesByKey(Cstr(StartDate.DateOnly),True)

	Print Cstr(vc.Count) " docs found for " & Cstr(StartDate.DateOnly)

	Call StartDate.AdjustDay(1)

	Stop

Next

Stop

My documents may have multivalues in the field - so I explode it in the column. I’m sure this is part of the issue (just realized I should have included that in my original post)

What I think may work is this:

If (EndDate.TimeDifference( modifiedDateTime )/86400) < 5 And (EndDate.TimeDifference( modifiedDateTime )/86400) >=0 Then

			boolDate=True

			Print "END DATE: " &Cstr((EndDate.TimeDifference( modifiedDateTime )/86400) ) & " is < 5 & >=0"

			Print "START DATE: " & Cstr((StartDate.TimeDifference( modifiedDateTime )/86400) ) 

		Else

			boolDate=False

		End If

		

		

		While boolDate=True...

but I just need to break out of my Wend - how do I do that? Or probably use a sub routine…

Subject: RE: using CreateViewNavFromCategory not working

ideally I would like to step through the entire (unfiltered) view and just pull the dates and subcategories I need. I will try using a sub routine - that would solve most of my anguish I think, right? If the date falls in between those dates then start populating mail message…

Here is what “works” (it’s ugly):

my view selection formula (more dates show up than I want because multiple dates entered in the multivalued field):

x:=@TextToTime(@Explode(dateout));

SELECT x>= @Adjust(@Now; 0; 0; 1-@Weekday(@Now); 0; 0; 0) & x<= @Adjust(@Now; 0; 0; 6-@Weekday(@Now); 0; 0; 0)

First Column:

@TextToTime(@Explode(dateout))

Sub Initialize

’ Agent Runs On Monday morning, gives schedule for the week

On Error Goto errtrap

Dim dbug As New NotesLog("Agent log")

Call dbug.OpenAgentLog

Dim s As New NotesSession     

Dim dc As NotesDocumentCollection

Dim db As notesdatabase 			' CURRENT DB

Dim dbERR As notesdatabase 	' CURRENT DB

Dim vc As NotesViewEntryCollection	

Dim view As notesview

Dim doc As notesdocument



Dim DayofWeek As String



Dim nav As NotesViewNavigator

Dim searchView As notesview

Dim entry As NotesViewEntry



Dim agent As NotesAgent

Dim n As String	



Dim gmtdate As String



Dim docID As String ' Variable to hold document Universal ID

Dim ReplicaID As String ' Variable used to build Replica ID line in .NDL file

Dim HintServer As String ' Variable used to build hint server line in .NDL file

Dim ViewID As String ' Variable used to build view line in .NDL file

Dim NoteID As String ' Variable used to build document line in .NDL file



Dim rtitem As NotesRichTextItem

Dim object As NotesEmbeddedObject

Dim filename As String



Dim columnValue1 As Variant

Dim columnValue2 As Variant

Dim xdate As Variant

’ Option Declare

Dim sendto As Variant

Dim ERRRTITEM As NotesRichTextItem

Dim ERRMEMO As NotesDocument

Dim ERRTXT As String



Set agent = s.CurrentAgent

If agent Is Nothing Then dbug.LogAction("agent is not set") Else dbug.LogAction("agent is set")	

n = agent.Name



Set db=s.CurrentDatabase

Call dbug.LogAction("db is set")



Set view = db.GetView("Calendar")

If view Is Nothing Then dbug.LogAction("view is not set") Else dbug.LogAction("view is set")



' create ndl here	

			'++++++++++++++++++++++++++++++++++++++++++++++

%REM

’ Verify that the document current exist in the database

If doc.IsNewNote Then

’ Document has not been saved, warn user and exit routine

	'		Msgbox "This document has not been saved." & Chr$(10) & Chr$(10) & "Please save prior to mailing link!", 4112, "New Document"

	ERRtxt=	"This document has not been saved." & Chr$(10) & Chr$(10) & "Please save prior to mailing link!"

	Call dbug.LogAction(ERRtxt)

	Print ERRtxt				

	Goto errtrap

Else 

’ Lets get the documents I.D.

	docID = doc.UniversalID 

	Call dbug.LogAction("UNID: " & docID)

End If

%END REM

’ Lets ensure that user is not attempting to send a link of a local database

If db.server = "" Then

’ This is a local database and mailed link will not work, warn user and exit routine

’ Msgbox “You are not allowed to send a link of a local database”, 4112, “Local Links Not Allowed”

	ERRtxt= "You are not allowed to send a link of a local database"

	Call dbug.LogAction(ERRtxt)				

	Print ERRtxt								

	Goto errtrap

Else

’ Build Replica line for .NDL file format = <REPLICA 8525643D:0069F618>

	ReplicaID="<REPLICA " & Left$(db.ReplicaID, 8) & ":" & Right$(db.ReplicaID, 8) & ">"

	Call dbug.LogAction("ReplicaID: " + ReplicaID)

End If





ViewID = ""

' Lets verify that a default view exist in this database as a view handle is need for the .NDL file	

' Build View line for .NDL file format = <VIEW OF0BA62705:23C5A6D0-ON8525643D:006A3AA7>

ViewID = "<VIEW OF" & Left$(view.UniversalID, 8) &":"&Mid$(view.UniversalID, 9, 8)&"-"&"ON"&Mid$(view.UniversalID, 17, 8)&":"&Right$(view.UniversalID, 8)&">" 

Call dbug.LogAction("ViewID: " + ViewID)

%REM

Forall x In db.Views 'Use ForAll to loop through each view in the database until the default is found

	If Not(x.name="My Favorites" Or x.name="(My Favorites)") Then

		If x.isprivate=False Then

			If x.IsDefaultView Then 'Test each view to see if it is the default view

’ Build View line for .NDL file format =

				ViewID = "<VIEW OF" & Left$(x.UniversalID, 8) &":"&Mid$(x.UniversalID, 9, 8)&"-"&"ON"&Mid$(x.UniversalID, 17, 8)&":"&Right$(x.UniversalID, 8)&">" 

				Call dbug.LogAction("ViewID: " + ViewID)

				Exit Forall 'Once the default view is found, break out of the loop

			End If

		End If

	End If

End Forall

%END REM

’ Lets ensure that our view handle for the .NDL file was built

If ViewID = "" Then 

’ View handle was never built so link would give a view error, warn user and exit routine

		'	Msgbox "This database does not contain a default view." & Chr$(10) & Chr$(10) & "Please contact your database manager!", 4112, "Default View Not Found"

	ERRtxt= "This database does not contain a default view." & Chr$(10) & Chr$(10) & "Please contact your database manager!"

	Call dbug.LogAction(ERRtxt)				

	Print ERRtxt								

	Goto errtrap

End If

%REM

’ Build Note line for .NDL file format =

NoteID = "<NOTE OF" & Left$(docID, 8) &":"&Mid$(docID, 9, 8)&"-"&"ON"&Mid$(docID, 17, 8)&":"&Right$(docID, 8)&">" 

Call dbug.LogAction("NoteID: " + NoteID )

%END REM

’ Build Hint Server line for .NDL file format = CN=FTLNSDEV/OU=DEV/O=FTG

HintServer = "<HINT>"& db.server &"</HINT>"

Call dbug.LogAction("HintServer:" & HintServer )

‘’ Assign a file name for the .NDL file that we will be mailing

’ Write out link data to C:\link.ndl

Dim fileNum As Integer

fileNum% = Freefile()

'Open “c:\test\test.html” For Output As fileNum%

fileName$ = "c:\temp\CalendarLink.ndl"

Call dbug.LogAction("filename: " & filename$)			

Print filename$

Open filename$ For Output As fileNum%

Call dbug.LogAction("file opened for input")

Print "file opened for input"

Print #fileNum%, "<NDL>"

Print #fileNum%, Cstr(ReplicaID)

Print #fileNum%, Cstr(HintServer)

Print #fileNum%, Cstr(ViewID)

’ Print #fileNum%, Cstr(NoteID)

Print #fileNum%, "</NDL>"

Close fileNum%



Print "file created"				

Call dbug.LogAction("ndl file created")				

'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Dim memo As NotesDocument



Set memo = New NotesDocument(db)

Call dbug.LogAction("memo is set")

’ memo.Subject = "Schedule for the week of " & Cstr(Date)

memo.Principal=db.Title



Set rtitem = New notesrichtextitem(memo, "Body")

Call dbug.LogAction("set new rtitem")



Set object = rtitem.EmbedObject ( EMBED_ATTACHMENT, "", fileName$, "Filler" )

Call dbug.LogAction("set object")



Set searchView = db.GetView("DAYSOUTNEXTWEEK")

Call dbug.LogAction("search is set")



Dim StartDate As New NotesDateTime(Date)

Dim wd As Integer



wd%=Weekday(StartDate.DateOnly)

Call StartDate.AdjustDay(2-wd)

Stop





xdate=StartDate.DateOnly



Dim EndDate As New NotesDateTime(StartDate.DateOnly)

Call EndDate.AdjustDay(4)



Dim boolDate As Boolean

Dim modifiedDateTime As NotesDateTime



Set modifiedDateTime = New NotesDateTime( xdate )

Print Cstr(EndDate.TimeDifference( modifiedDateTime )/86400) & " days"





Set nav = searchView.CreateViewNav()

Call dbug.LogAction("viewnav is set")





memo.Subject = "Schedule for the week of " & Cstr(StartDate.DateOnly) & " - " & Cstr(EndDate.DateOnly)

Call dbug.LogAction(" week of " & Cstr(StartDate.DateOnly) & " - " & Cstr(EndDate.DateOnly))



Set vc=searchView.AllEntries

Call dbug.LogAction("vc is set")



Call rtitem.AddNewline(1)



If vc.Count=0 Then

	

	Print "everyone is here"

	Call dbug.LogAction("everyone is here")	

	Call rtitem.AddNewline(1)

	Call rtitem.AppendText("There are no scheduled attendance records for this week.")

	Goto sendMail

Else

	

	Call rtitem.AddNewline(1)				

	Call rtitem.AppendText("The following associates will not be here the week of " & Cstr(StartDate.DateOnly) & " - " & Cstr(EndDate.DateOnly))

	Call rtitem.AddNewline(2)				

	

	Stop

	

	Set entry = nav.GetFirst

	

	If entry Is Nothing Then 

		'do something

		Print "everyone is here"

		Call dbug.LogAction("everyone is here")	

		Call rtitem.AddNewline(1)

		Call rtitem.AppendText("There are no scheduled attendance records for this week.")

		Goto sendMail

		

	Else	

		

		If (EndDate.TimeDifference( modifiedDateTime )/86400) < 5 And (EndDate.TimeDifference( modifiedDateTime )/86400) >=0 Then

			boolDate=True

			Print "END DATE: " &Cstr((EndDate.TimeDifference( modifiedDateTime )/86400) ) & " is < 5 & >=0"

			Print "START DATE: " & Cstr((StartDate.TimeDifference( modifiedDateTime )/86400) ) 

		Else

			boolDate=False

		End If

		

		

		While boolDate=True				

			If entry.IsCategory Then				

				Call rtitem.AddNewline(1)

				columnValue1 = entry.ColumnValues(0)

				

				If Isarray(columnValue1) Then

’ Print “entry.ColumnValues =”& Implode(columnValue1, “,”)

					xdate= Implode(columnValue1, ",")

				Else 

					Print "entry.ColumnValues ="& columnValue1

					xdate=columnValue1					

’ Call rtitem.AppendText(columnValue1)

				End If

				

				Set modifiedDateTime = New NotesDateTime( xdate )

				Print Cstr(EndDate.TimeDifference( modifiedDateTime )/86400) & " days"

				Stop

				

				If (EndDate.TimeDifference( modifiedDateTime )/86400) < 5 And (EndDate.TimeDifference( modifiedDateTime )/86400) >=0 Then

					boolDate=True

					Print "END DATE: " &Cstr((EndDate.TimeDifference( modifiedDateTime )/86400) ) & " is < 5 & >=0"

					Print "START DATE: " & Cstr((StartDate.TimeDifference( modifiedDateTime )/86400) ) 

				Else

					boolDate=False

					Goto sendMail

				End If

%REM

			If (StartDate.TimeDifference( modifiedDateTime )/86400) < 5  Then

				Print "START DATE: " & Cstr((StartDate.TimeDifference( modifiedDateTime )/86400) ) & " is less than 5"

’ Goto next entry

			Elseif (StartDate.TimeDifference( modifiedDateTime )/86400) > 5  Then

				Print "START DATE: " &Cstr((StartDate.TimeDifference( modifiedDateTime )/86400) ) & " is greater than 5"

			End If

%END REM

				Call rtitem.AddNewline(1)

				Call rtitem.AppendText(xdate)

				Call rtitem.AddNewline(1)

			Else				

				

				If (EndDate.TimeDifference( modifiedDateTime )/86400) < 5 And (EndDate.TimeDifference( modifiedDateTime )/86400) >=0 Then

	'				Print "END DATE: " &Cstr((EndDate.TimeDifference( modifiedDateTime )/86400) ) & " is less than 5 and greater than or equal to 0"

	'				Print "START DATE: " & Cstr((StartDate.TimeDifference( modifiedDateTime )/86400) ) 

		''	Elseif (EndDate.TimeDifference( modifiedDateTime )/86400) > 5  Then

				Else 

					Print "END DATE: " &Cstr((EndDate.TimeDifference( modifiedDateTime )/86400) ) & " is greater than 5 and less than 0"	

					Print "START DATE: " & Cstr((StartDate.TimeDifference( modifiedDateTime )/86400) ) 

					Goto nextentry

’ Goto send mail

				End If

				

				columnValue2 = entry.ColumnValues(1)

				Call rtitem.AddTab(1)

				If Isarray(columnValue2) Then

					

					Print "entry.ColumnValues ="& Implode(columnValue2, ",")

					Call rtitem.AppendText(Implode(columnValue2, ","))

				Else 

					Print "entry.ColumnValues ="& columnValue2

					Call rtitem.AppendText(columnValue2)

				End If

				Call rtitem.AddNewline(1)				

			End If

nextentry:

			Set entry=nav.GetNext(entry)

'		Set entry=nav.GetNextDocument(entry)

		Wend

	End If

End If

sendMail:…

Subject: RE: using CreateViewNavFromCategory not working

I feel like I am cheating a little when I do this but this works:

For i=1 To 5

	cmd={@DbLookup( "" : "NoCache" ; "} & db.Server & {" : "} & path & {" ; "DAYSOUTNEXTWEEK" ; ([} & modifiedDateTime.DateOnly & {]) ; 2);}				

	

	results = Evaluate(cmd)

	Call rtitem.AddNewline(1)

	Call rtitem.AppendText( modifiedDateTime.DateOnly)

	Call rtitem.AddNewline(1)

	

	If Isempty(results) Then	

'		Call rtitem.AddNewline(1)

		Call rtitem.AddTab(1)

		Call rtitem.AppendText("No scheduled absences.")

	Else

		

		Forall v In results

			Call rtitem.AddTab(1)

			Call rtitem.AppendText(v)

			Call rtitem.AddNewline(1)

		End Forall

		

	End If

	Call rtitem.AddNewline(1)

	Call  modifiedDateTime.AdjustDay(1)

Next