Pregunta

Tengo problemas con este agente: he usado exactamente la misma técnica en un agente similar, pero por alguna razón, el cliente informa un error con esta línea:

Set dc = locView.GetAllDocumentsByKey(key, True)

Dice que la variable de objeto no está establecida. ¿Puedes ayudar a encontrar lo que me estoy perdiendo?

Gracias por adelantado.

%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

Final

¿Fue útil?

Solución

Lo más probable es que esta línea esté fallando:

Set locView = locDb.GetView("byNameDateLocCode")

¿Qué ves para LocView en el depurador? Si no es una vista válida, verifique el nombre de la vista para asegurarse de que coincida con lo anterior, y verifique el ACL de la base de datos y cualquier restricción en la vista para asegurarse de que tenga los permisos requeridos. Si el agente se está ejecutando como agente web, asegúrese de que el firmante y/o el servidor tenga los permisos requeridos (dependiendo de su configuración para la identidad de tiempo de ejecución del agente). Si la base de datos LOCDB está en un servidor diferente al que se ejecuta el agente, asegúrese de que el servidor de "servidor de confianza" le otorgue al servidor de agente.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top