Display the Attachment Name in Each Column of the View and Extract Attachments from HCL Notes Documents Without Deletion and Organized by Document ID Using LotusScript

Description :

In many HCL Notes applications, documents often include multiple file attachments embedded within Rich Text fields. In certain scenarios — such as archiving, data processing, or backups — administrators and developers may need to extract these attachments while preserving the original documents and data structure within the Notes database.

This blog post provides a step-by-step guide on how to achieve the requirement.

  1. Display attachment names in a custom view for easier identification and tracking.

  2. Extract all file attachments from selected Notes documents using LotusScript.

  3. Save each document’s attachments into a dedicated folder named after its unique Document ID (UNID or NoteID).

  4. Ensure that no changes or deletions are made to the documents or attachments in the database.

The approach outlined here allows for a clean and non-destructive extraction process, helping maintain the integrity of your HCL Notes environment.

Key Requirements

To implement this solution, the following requirements should be met:

The HCL Notes database must remain unaltered — no deletion or modification of documents or attachments.

Each document’s attachments will be saved in a separate folder, named after the document’s UNID or NoteID.

A custom view will display attachment names in individual columns for user-friendly access and monitoring.

Part 1: Displaying Attachment Names in a View

Step 1: Create a New View

Design a view to list documents containing attachments.

Add multiple columns to display individual attachment names.

Step 2: Add Column Formulas

For each column, increment the ATT_INDEX to show subsequent attachment names:

Column 1 Formula:
ATT_INDEX := 1;
ATT_LIST := @AttachmentNames;
@If(ATT_LIST = “”; @Return(“”); “”);
@If(@Elements(ATT_LIST) < ATT_INDEX; @Return(“”); “”);
@Subset(@Subset(ATT_LIST; ATT_INDEX); -1)

Column 2 Formula:
ATT_INDEX := 2;
ATT_LIST := @AttachmentNames;
@If(ATT_LIST = “”; @Return(“”); “”);
@If(@Elements(ATT_LIST) < ATT_INDEX; @Return(“”); “”);
@Subset(@Subset(ATT_LIST; ATT_INDEX); -1)

Column 3 Formula:
ATT_INDEX := 3;
ATT_LIST := @AttachmentNames;
@If(ATT_LIST = “”; @Return(“”); “”);
@If(@Elements(ATT_LIST) < ATT_INDEX; @Return(“”); “”);
@Subset(@Subset(ATT_LIST; ATT_INDEX); -1)

Note: Repeat this pattern for additional columns by incrementing the ATT_INDEX value.
:warning: Note: This formula works best when each Rich Text field contains only one attachment. If a Rich Text field contains multiple attachments, it will consider the first attachment from that field. As a result, only one attachment per field may be displayed in the view.

Part 2: Extracting Attachments Using LotusScript

Step 1:
Create an Action Button in the View
Button Name: Extract Attachments

Step 2: Add the Following LotusScript Code

======================================
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim collection As NotesDocumentCollection
Dim attach As NotesEmbeddedObject
Dim fileCount As Integer
Dim result, fname, path As String

Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments
Set doc = collection.GetFirstDocument

path = "D:\ATTACHMENTS"

While Not doc Is Nothing
fname = doc.NoteID ’ Or use doc.UniversalID if preferred
Mkdir path & fname
result = path & fname

Forall i In doc.Items
If Lcase(i.Name) = “$file” Then
Set attach = doc.GetAttachment(i.Values(0))
If Not attach Is Nothing Then
Call attach.ExtractFile(path & fname & "" & i.Values(0))
End If
End If
End Forall

Set doc = collection.GetNextDocument(doc)
Wend
Msgbox “The extraction is done successfully.”

======================================
Step 3: Create the Output Folder

Before running the script, manually create the following base output folder:

File Path: D:\ATTACHMENTS

Note: Please ensure that the “ATTACHMENTS” folder under the D drive exists and is empty before extraction. Remove any existing subfolders if present.

Step 4: Run the LotusScript

Open the custom view in the Notes client.

Select one or more documents.

Click the “Extract Attachments” button.

Attachments will be saved into individual subfolders within D:\ATTACHMENTS, named after each document’s NoteID (or UNID, if modified).

By following this approach, developers can extract document attachments in a clean, organized, and non-invasive manner — ideal for processing and archiving tasks within HCL Notes applications.

Disclaimer : This solution is provided as an illustrative example and has been tested in a controlled environment. We strongly recommend adapting and validating the code within your own development and QA environments before deploying it to production. Please note that this method is not officially supported by HCL Product Support. Any customization is undertaken at your own discretion.

Note : It has been considered and assumed that only one attachment is included in the Notes document.

1 Like