Search code examples
lotus-noteslotus-dominolotusscriptlotusagent

Refresh lotus documents with scheduled agent


I have an error on a computed for display text field. For Each document, i open it in edit mode and resave to correct it. I have the same problem on many databases and documents. I tried to correct it with an agent over the entire base with the function EditDocument in uiworkspace . As follows:

Option Public
Option Declare

Sub Initialize

Dim session As New NotesSession
Dim db As NotesDatabase
Dim col As NotesDocumentCollection
Dim view As NotesView
Dim doccand As NotesDocument
Dim doc As NotesDocument
Dim result As Integer
Dim uiwks As New NotesUIWorkspace
Dim uidoc As NotesUIDocument

Set db  = session.Currentdatabase
Set col = db.Unprocesseddocuments
Set docCand =  col.getfirstdocument

On Error Resume next

While Not docCand Is Nothing
    Set uidoc =  uiwks.Editdocument(True, docCand)
    Call uidoc.save
    Call uidoc.close(True)
    Set docCand =  view.getNextdocument(docCand)
Wend

End Sub

This function corrects the problem only when I start it from my Notes client. It does not work as a scheduled task in the domino server. I tried with computewithform without uiworkspace and it does not work either. Anyone have a method to refresh with edit and save document in scheduled agent?


Solution

  • computed for display text field

    Such type of fields are not saved in documents, it's kind of same thing as a Computed Text.

    About your solution:

    NotesUIWorkspace and EditDocument can't be use in a schedule agents that run in background (i.e. on server)but only from UI (that's why it works when you run LN).

    What you need to do is to use ComputeWithForm method from NotesDocument. It will refresh documents in background (no need to open/save it).

    While Not docCand Is Nothing
        Call docCand.ComputeWithForm(False, False)
        Call docCand.save
        Set docCand = col.getNextdocument(docCand)
    Wend
    

    Notice, in your script there is an issue, you are trying to get next document from a view which is not initialized. I guess you want to use col instead.

    Set docCand =  view.getNextdocument(docCand)