Prevent documents from being pasted into an application

Today I remembered an workaround in Lotusscript I used in the past to prevent documents from being pasted into an application. The key is an Agent set to be triggered ‘When documents are pasted’.

The code of the Agent looks like this (for the ease of reading no error handling has been included):

Sub Initialize
Dim session As NotesSession
Dim db As NotesDatabase
Dim colPasted As NotesDocumentCollection
Dim doc As NotesDocument
Dim docRemove As NotesDocument
Set session = New NotesSession
Set db = session.CurrentDatabase
Set colPasted = db.UnprocessedDocuments
Set doc = colPasted.GetFirstDocument
Do While Not doc Is Nothing
Set docRemove = doc
Set doc = colPasted.GetNextDocument(doc)
Call docRemove.RemovePermanently (True)
Msgbox "You are not authorised to paste documents into this application.",16,"Error"
End Sub

The key in this solution is the usage of two NotesDocument objects, doc holding the current document to work on and docRemove containing the actual document to be removed. If doc would have been remove prior to using the GetNextDocument method of the collection, the collection would be unable to identify the next document.

I believe that there are other solutions out there. One possible option would be to immediately flag the pasted document to not show up in any view any more and to delete via a background maintenance agent. It would be interesting to hear how others are preventing documents from being pasted.

5 thoughts on “Prevent documents from being pasted into an application

  1. If you want to delete the pasted documents when they are pasted, I think you can use an agent that run when documents are pasted with this simple formula:


    It has few code. It is more easy to maintain.

    Or not?

  2. Hey Chemalo,
    I fully agree with you. And I can not even think of any error handling for your solution 🙂 .
    The only disadvantage with your way is the missing client interaction, informing the user that s(he) is unable to paste documents. A @Prompt in a formula language agent would be displayed for each individual document that has been pasted – the usual @Formula disadvantage.
    Thanks for sharing this.

  3. Hi cubetoon,

    You are right, the formula will pop up every time, but when I applied and run your code in my Notes 6.5 client, it always gets the red pop and crashes. Wired, but using formula doesn’t encounter this problem. Which version of Notes are you using? Thanks.

  4. Jia Ji Chen,

    I am on 7.0.x and 8.x. But the script should also be working on 6.5. May I suggest commenting out one of the last two lines in the loop, one by one to see which one is causing it?

  5. Another way around this would be to put your code in the QueryPaste event of individual views. As this runs before the document is pasted there is no need to delete the document, just give the user an error message indicating that they can’t paste in this database then exit the sub. The only drawback of this method is that it must be added to all views individually that users can access. This will work in all versions of Notes.

Leave a Reply

Your email address will not be published. Required fields are marked *