Question

I am having issues with this agent - i have used the exact same technique in a similar agent but for some reason, the client is reporting an error with this line:

Set dc = locView.GetAllDocumentsByKey(key, True)

It says that the object variable is not set. Can you help to find what I am missing?

Thanks in advance.

%REM
Sub as_archiveOldDocuments
Description:
This agent archives documents that are more than one week old.
This is so that the dataset used is kept current - view selections only select documents
whose archived field value is equal to zero. For that reason, this agent detects whether
or not a document in the set is more than a week old. If it is, the Archived field is
marked as '1'.

Function calls: N/A
Sub calls: N/A
Called in event: N/A
Called by: ag_archiveOldDocuments

%END REM
Public Sub as_archiveOldDocuments

Dim s As NotesSession
Dim locDb As New NotesDatabase(****)
Dim locView As NotesView
Set locView = locDb.GetView("byNameDateLocCode")
Dim dc As NotesDocumentCollection
'Set dc = locDb.CreateDocumentCollection()
Dim key (0 To 1) As Variant
Dim archiveDate As NotesDateTime
Set archiveDate = New NotesDateTime(Today)
Call archiveDate.AdjustDay(-7)
Dim thisDoc As NotesDocument
Dim unarchived As Integer
Let unarchived = "0" 

'populate key to build document collection, then build it
key(0) = archiveDate.DateOnly
key(1) = unarchived
Set dc = locView.GetAllDocumentsByKey(key, True)

'find first document in the collection
Set thisDoc = dc.GetFirstDocument()

'while the doc collection exists
While Not dc Is Nothing

    'if the date value in the document is less than the archiveDate value specified (today -7)
    If thisDoc.Date <= archiveDate.DateOnly Then

        'replace the archived value (which will be '0') with '1'
        Call thisDoc.ReplaceItemValue("Archived", "1")
        Call thisDoc.ComputeWithForm(False,True)
        Call thisDoc.Save(True, False, False)

    End If

    Set thisDoc = dc.GetNextDocument(thisDoc)

Wend

End Sub

Was it helpful?

Solution

Most likely this line is failing:

Set locView = locDb.GetView("byNameDateLocCode")

What do you see for locView in the debugger? If it is not a valid view, check the view name in order to make sure it matches the above, and check the database ACL and any restrictions on the view to make sure that you have the required permissions. If the agent is running as a web agent, make sure that the signer and/or the server has the required permissions (depending on your setting for the agent's runtime identity). If the database locDb is on a different server than the one where the agent is running, make sure that the agent server is granted 'Trusted Server' rights by the target server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top