0
votes

I am still new at Notes, so I'm still not familiar with every function. I will briefly explain my process.

I have a list of documents on "List" view. I want to copy all current documents to another view, let's say "Batch" as a new document, and lock flag all document on "List" view. I will edit the new document inside "Batch", and when I click save, this new document will save as new current documents, and for the old current document, it will remove to "old" view. So I can see new edit document and old document.

As for now, I found out this link for lock flag but I do not know how to create for all documents

My question is, do I need to create a button on my view to copy all document to another view? How can I copy all document to a new view and save as new document? Can anyone advise any function that can I add to the process? Thanks in advance!

1

1 Answers

2
votes

I would approach this by first setting viewList.refresh to false: this stops the view index from being refreshed as you loop through the view, especially if you make an edit that changes something in the selection formula.

Loop through each document, with document.copy create the archive by setting the Form parameter.

At the end of the loop, and in the terminate event and/or error handler, set viewList.refresh back to true again.

This way you only need the lock the original document if you're going to edit it, and that's best done inside the loop for the shortest duration, rather than trying to lock all documents for the duration of the loop. If you go down this route, also have a document unlock in the terminate event and/or error handler.

Theoretically the actions I've suggested terminate event and error handler don't need to be duplicated: just my cautious nature.

Function CopyDoc( docOld As NotesDocument, dbThis As NotesDatabase) As NotesDocument
    Dim docNew As NotesDocument
    On Error GoTo Handler

    Set docNew  = docOld.copyto(dbThis)
    Call docOld.lock()
    docOld.Form = "Archive"
    Call docOld.Save(True,True)
    Call docOld.unlock()
    'docNew Edits You Want To Make
    Call docNew.Save(True,True)
    Set CopyDoc = docNew
e:  Exit Function

Handler:
    Call docOld.unlock()
    'additional logging for diagnostics
    Resume e
End Function