Open an attachment from Lotus Notes view

2 minute read

I have a Lotus Notes database with documents that contain attached files, it is called the Document Manager. It is quite convenient, however, when I need to see the attached file, I first need to open the Notes document that contains this attachment and from there open the attachment itself by double clicking it. I know that I could open attachments from the view directly by assigning the launch action “Open first attachment” to the form, but I need to have a working form to be able to see and modify my metadata. So, since with Notes 8.X we have an option to put view actions into the context popup menu, I decided to make it this way. However, I soon found that there’s no way to open an attachment using @formula in the view action and there is no simple way to open a first attachment from LotusScript view action code.

After some time I managed to find a workaround. It works without extracting a file to the local disk and doesn’t need to know what application needs to be executed to open the attachment.

What I had to do is to create another form, say “DocLaunch” with “launch first attachment” option enabled in it. It also has the Body rich text field. My assumption also was that I know the attachment name, since it is stored in the original document computed field. So the final action code is:

<blockquote class="tr_bq">
Sub Click(Source As Button)
Dim ws As New NotesUIWorkspace
Dim uiview As NotesUIView
Dim id As String

Set uiview = ws.CurrentView
id = uiview.CaretNoteID

Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument

Set db = session.CurrentDatabase
Set doc = db.GetDocumentByID(id)
If doc Is Nothing Then 
Msgbox “Nothing selected”
Exit Sub
End If

Dim rt As NotesRichTextItem
Set rt = doc.GetFirstItem(“Body”)
Dim obj As NotesEmbeddedObject
Set obj = rt.GetEmbeddedObject(doc.FILENAME_C(0))
If obj Is Nothing Then 
Msgbox “Attachment missing”
Exit Sub
End If

Dim newdoc As NotesDocument
Set newdoc = db.CreateDocument
newdoc.Form = “DocLaunch”
Dim newrt As NotesRichTextItem
Set newrt = newdoc.CreateRichTextItem(“Body”)
Call newrt.AppendRTItem(rt)
Call ws.EditDocument(False, newdoc)

End Sub
</blockquote>Basically it opens the selected document, gets the attachment from it, creates a new document, creates a new rich text item in this document and copies the attachment to this item. It all happens without saving anything to the database or local disk. New document gets the auto-launch form assigned and then opened in read mode. Viola, all done :)

Updated: