As I promised in my previous entry, I will show how to use the Windows clipboard functionality in a Notes application.
We have a knowledgebase, where information for different departments is posted. A very typical and simpel Notes application, in other words. But some users requested a simpler way to create nice doclinks, so I listened and created two buttons on the document form.
The first button is 'Copy Link', it will simply collect information about the open document (database server, filename and path and UNID of the document. This information is then just stored in the cliboard as a delimited string.
The second button is 'Paste Link'. It will read the delimited string from the clipboard, get a handle to the document and create a nice doclink. The title of the document is also pasted into the document.
To support this functionality, you also have to create a form called 'doclink', where the only content is a RichText field called "Body". Make sure there is not even a linebreak after the field.
Below is the actual code. It requires the script library I posted earlier. Hope this can help someone.
Button 'Copy Link':
Use "Class.Win32.ClipBoard"Sub Click(Source As Button) Dim ws As New NotesUIWorkspace Dim uidoc As NotesUIDocument Dim clipboard As WindowsClipboard Dim clipdata As String Set clipboard = New WindowsClipboard() Set uidoc = ws.CurrentDocument clipdata="NotesData~" & ws.CurrentDatabase.Database.Server clipdata = clipdata & "~" & ws.CurrentDatabase.Database.FilePath clipdata = clipdata & "~" & uidoc.Document.UniversalID clipboard.Contents = clipdata Msgbox "Document info has been stored. You can now" & Chr$(10) & _ "use the 'Paste Link' button in IT Support db or" & Chr$(10) & _ "your mail file to create a link to this document.",,"Success"End Sub
Button 'Paste Link':
Use "Class.Win32.ClipBoard"Sub Click(Source As Button) ' *** Create and insert a doclink at the insertion point Dim session As New NotesSession Dim ws As New NotesUIWorkspace Dim thisdoc As NotesUIDocument Dim tempuidoc As NotesUIDocument Dim db As NotesDatabase Dim doc As NotesDocument Dim tempdoc As NotesDocument Dim linkdb As NotesDatabase Dim temprt As NotesRichTextItem Dim dbname As String Dim servername As String Dim unid As String Dim clipboard As WindowsClipboard Dim clipdata As String Dim clipargs As Variant ' Array to hold data from clipboard Set thisdoc = ws.CurrentDocument Set db = session.currentdatabase Set clipboard = New WindowsClipboard() clipdata = clipboard.Contents If clipdata="" Then Msgbox "No clipboard info found." Exit Sub Elseif Instr(clipdata,"NotesData~")=0 Then Msgbox "No doclink info in clipboard." Exit Sub End If clipargs = Split(clipdata,"~") servername = clipargs(1) dbname = clipargs(2) unid = clipargs(3) Set linkdb = session.GetDatabase(servername, dbname, False) If linkdb Is Nothing Then Msgbox "Could not find " & dbname & " on " & servername,,"Not Found" Exit Sub End If Set doc = linkdb.GetDocumentByUNID(unid) If doc Is Nothing Then Msgbox "Could not located document.",,unid Exit Sub End If ' Now the awkward bit: the only way to insert a doclink into RT that you ' are editing is to paste it. The only way to get a pastable doclink into ' the clipboard is to copy one from an existing document so first we make ' a doclink in an RT field that links to the document. Set tempdoc = New NotesDocument(db) ' Form that will only contain the field with the doclink and NOTHING else. Call tempdoc.ReplaceItemValue("Form","doclink") Set temprt = New NotesRichTextItem(tempdoc,"body") Call temprt.AppendText(doc.KBFull(0) & " - " & doc.Topic(0) & " ") Call temprt.AppendDocLink(doc, doc.Topic(0)) ' This doc must be saved otherwise the display doesn't work Call tempdoc.Save(True, False) ' Now "display" the document so we can grab the doclink Set tempuidoc = ws.EditDocument(False, tempdoc) ' Select and copy the content Call tempuidoc.SelectAll Call tempuidoc.Copy ' We should have the doclink inthe clipboard ' Close and throw away the temporary document Call tempuidoc.Close Call tempdoc.Remove(True)
Call thisdoc.Paste ' Paste the doclinkEnd Sub