Tuesday, 21 February 2017

IBM Notes Tip: Prevent Pasting of Documents in Notes Views through LotusScript Agents

Last week I was asked to ensure through LotusScript Agents that users no longer have the possibility to paste documents in the Notes Views within a specific Notes Database. As always there are several ways to achieve this. In the following I created two LotusScript Agents which ensure that pasting of documents in all views within the specific Notes database no longer is possible. All pasted documents will be immediately removed by the Agents.

A. Agent Delete Pasted Documents
Option Public
Sub Initialize
Dim s As NotesSession
Dim db As NotesDatabase
Dim agent As NotesAgent
Dim coll As NotesDocumentCollection
Dim doc As NotesDocument

Set s = New NotesSession
Set db = s.CurrentDatabase
Set coll = db.UnprocessedDocuments

If coll.Count > 0 Then
Set agent = db.GetAgent("DeletePastedDocumentsRemove")
Set doc = coll.GetFirstDocument
While Not(doc Is Nothing)
Call agent.RunOnServer(doc.NoteID)
Set doc = coll.GetNextDocument(doc)
Wend
End If

End Sub


B. Hidden Agent (DeletePastedDocumentsRemove)

Option Public
Sub Initialize
Dim s As NotesSession
Dim db As NotesDatabase
Dim agent As NotesAgent
Dim doc As NotesDocument

Set s = New NotesSession
Set db = s.CurrentDatabase
Set agent = s.CurrentAgent
Set doc = db.GetDocumentByID(agent.ParameterDocID )

Call doc.Remove(True)
End Sub


Another option is to use the Querypaste Event. However, this must be set per View
and it is only advisable to use if not in all Views in a specific database the possibility for pasting documents should be disabled.

Sub Querypaste(Source As Notesuiview, Continue As Variant)
Continue = False
End Sub

No comments:

Post a Comment