Overview : It is not directly possible to rename an attachment within a Notes document using built-in Lotus Notes features or LotusScript methods.
However, it can be achieved programmatically by extracting the attachment, renaming it externally, and reattaching it to the document.
An enhancement request has been submitted in the Domino Idea portal and past to introduce native support for renaming attachments:
Title : Rename attachments in a notes document
URL → Rename attachments in a notes document | HCL Domino Ideas Portal
Until such a feature is implemented, developers can use one of the two approaches below to accomplish this using LotusScript or Formula Language.
Approach 1: Using Formula Language
This approach uses Formula Language commands to:
- Extract an attachment from a rich text field.
- Prompt the user for a new name.
- Save it locally under the new name.
- Delete the old attachment from the document.
- Reattach the renamed file.
(a) Extract the Attachment
vAttachList := @AttachmentNames;
vSourceName := vAttachList;
vNewName := @Prompt([OkCancelEdit]; "New Filename"; "Please type in new file name"; vSourceName);
@Command([EditDocument]; "1");
@Command([EditGotoField]; "Attnm");
@Command([EditDetach]; vSourceName; "D:\\Test\\" + vNewName);
@Command([EditGotoField]; "Attnm");
@Command([EditSelectAll]);
@Command([EditClear]);
Explanation:
@AttachmentNamesretrieves the list of attachments.@Promptlets the user specify a new filename.@Command([EditDetach])extracts and renames the file.@Command([EditClear])clears the field after detachment.
(b) Add the Renamed Attachment Back
@Command([EditDocument]; "1");
@Command([EditGotoField]; "Attnm");
@Command([EditInsertFileAttachment]; "D:\\Test\\Test99.csv");
Explanation:
- The renamed attachment (
Test99.csv) is added back to the fieldAttnm.
Both parts of this approach can be implemented using two separate buttons in the Notes UI.
Approach 2: Using LotusScript
This approach uses LotusScript to automate the entire process:
- Extract the attachment to a local directory.
- Rename it using file operations.
- Remove the original attachment.
- Reattach the renamed file.
(c) Extract and Rename the Attachment
Dim ses As New NotesSession
Dim db As NotesDatabase
Dim doccoll As NotesDocumentCollection
Dim doc As NotesDocument
Dim rtitem As Variant
Set db = ses.CurrentDatabase
Set doccoll = db.UnprocessedDocuments
Set doc = doccoll.GetFirstDocument
Set rtitem = doc.GetFirstItem(“Attnm”)
If (rtitem.Type = RICHTEXT) Then
Forall o In rtitem.EmbeddedObjects
If (o.Type = EMBED_ATTACHMENT) Then ’ Extract and rename the attachment
Call o.ExtractFile(“D:\Test” & o.Source)
Filecopy “D:\Test” & o.Source, “D:\Test\Test9999.csv” ’ Remove old attachment from document
Call o.Remove
Call doc.Save(False, True)
End If
End Forall
End If
Explanation:
- Extracts the attachment from the rich text field
Attnm. - Renames it using the
FileCopymethod. - Removes the original embedded attachment.
- Saves the updated document (now without any attachments).
(d) Reattach the Renamed File
Dim ses As New NotesSession
Dim db As NotesDatabase
Dim doccoll As NotesDocumentCollection
Dim doc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim object As NotesEmbeddedObject
Set db = ses.CurrentDatabase
Set doccoll = db.UnprocessedDocuments
Set doc = doccoll.GetFirstDocument
Set rtitem = doc.GetFirstItem(“Attnm”)
Set object = rtitem.EmbedObject(EMBED_ATTACHMENT, “”, “D:\Test\Test9999.csv”)
Call doc.Save(False, True)
Explanation:
- Embeds the newly renamed file (
Test9999.csv) back into the same field. - Saves the updated document.
As in the previous approach, you can assign these scripts to separate buttons in the Notes form for easy use.
Summary
| Task | Formula Language | LotusScript |
|---|---|---|
| Extract Attachment | ||
| Rename Attachment | ||
| Delete Original | ||
| Reattach File | ||
| Automation Level | Medium | High |
Notes :
- Both approaches assume that the attachment resides in a Rich Text field named
"Attnm". - Update file paths as needed (
D:\Test\is used in examples). - Always back up documents before running scripts that modify attachments.
Disclaimer : This script is provided as a sample only and must be adapted for your organization’s environment and requirements. It has been tested in a controlled test setup. Always validate and review it with your Quality Assurance and Development teams before deploying it in production.