Search code examples
lotus-dominolotusscriptdomino-designer-eclipse

Domino Designer - The document is not in view <my view>


I have the following code, which loops through the documents in TestView1, and for each document in that view loops through the documents in TestView2, performing some action (outputs to a file).

For the sake of keeping the loops relatively timely (there's heaps of older documents and I only want those time stamped from today or an upcoming date), I have found the first document for the current date, and stored its UNID so that that document can act as a starting position for the inner loop (the documents in MyView2 are in chronological order).

The inner loop runs correctly the first time, but come the second loop, I get the error message "The document is not in view TestView2". I have added what line breaks my code.

Here is my code:

Dim sess As New NotesSession
Dim db As NotesDatabase
Dim rDoc As NotesDocument
Dim mDoc As NotesDocument
Dim rView As NotesView
Dim mView As NotesView
Dim unid As String
Dim todayDateTime As New NotesDateTime("Today")

Set db = sess.currentDatabase
Set rView = db.GetView("TestView1")
Set rDoc = rView.GetFirstDocument
Set mView = db.GetView("TestView2")
Set mDoc = mView.GetFirstDocument

Set mDoc = mView.GetFirstDocumentb 'Finds the UNID of the first document of the day
Do While Not (mDoc Is Nothing)
    Dim startDate As New NotesDateTime(mDoc.startDate(0))
    If startDate.DateOnly = todayDateTime.DateOnly Then
        unid$ = mDoc.UniversalID
        Exit Do
    End If
    Set mDoc = mView.GetNextDocument(mDoc)
Loop

While Not (rDoc Is Nothing) 'Outer Loop
    If rDoc.Site(0) = "SAMPLE" Then

        <CODE>

        If Not unid$ = "" Then
            Set mDoc = db.Getdocumentbyunid(unid$)
            While Not (mDoc Is Nothing) 'Inner Loop
                If mDoc.ResourceName(0) = rName$ Then

                    <PRINT TO FILE CODE>

                End If
                Set mDoc = mView.GetNextDocument(mDoc) <--- This line here breaks the code**
            Wend
        End If
    End If
    Set rDoc = rView.GetNextDocument(rDoc)
Wend

Would appreciate any help.


Solution

  • There is a more efficient approach: categorize your mView by ResourceName + StartDate and use mView.getDocumentByKey(keys, true) to access the first relevant document in mView:

    1. Add a first categorized column ResourceName to mView
    2. Add a second categorized column StartDate to mView
    3. Change your code to:
    Dim sess As New NotesSession
    Dim db As NotesDatabase
    Dim rDoc As NotesDocument
    Dim mDoc As NotesDocument
    Dim rView As NotesView
    Dim mView As NotesView
    Dim rName As String
    Dim keys(1) As Variant
    
    Set db = sess.currentDatabase
    Set rView = db.GetView("TestView1")
    Set rDoc = rView.GetFirstDocument
    Set mView = db.GetView("TestView2")
    
    While Not (rDoc Is Nothing) 
        If rDoc.Site(0) = "SAMPLE" Then
            rName = rDoc.ResourceName(0)
            ' <CODE>
            keys(0) = rName
            keys(1) = Today
            Set mDoc = mView.GetdocumentbyKey(keys, true)
            While Not (mDoc Is Nothing) 
                If mDoc.ResourceName(0) = rName Then 
    
                    ' <Print To FILE CODE>
    
                    Set mDoc = mView.GetNextDocument(mDoc)
                Else
                    Set mDoc = Nothing 
                End if
            Wend
        End If
        Set rDoc = rView.GetNextDocument(rDoc)
    Wend