Problem solve Get help with specific problems with your technologies, process and projects.

Your LotusScript questions answered

Our Notes/Domino development expert answers questions from our readers on how to use LotusScript to remove attachments and delete documents.

In this edition of the Domino mailbag, expert Mike Kinder answers LotusScript questions from our readers on removing attachments, deleting documents when they reach a certain age and more.

Have a question of your own? Send it along to

When removing a Notes document with an attachment, I'd like the ability to also remove the attachment. Can I use LotusScript code for this?

Kinder: First, I assume that you'd like to save any attachments on the document before deleting the document. If not, please remember that deleting the document will delete the attachment on the document when the document is deleted.

If you want to detach the attachment to the server's file system first, then delete the document, you can use the following LotusScript code.

Dim session As New NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
'use variant rather than NotesItem or 
'because it could be either, but when
 a NotesRichTextItem
'a variant will allow you to process the
 embedded objects
Dim item As Variant 
Set db = session.currentdatabase
'this will collect the document(s) you have 
selected from a view
'where you run this as an agent
Set dc = db.UnprocessedDocuments
If dc.Count > 0 Then
For d = 1 To dc.count
Set doc = dc.GetNthDocument(d)
'assumes item (field) is names BODY
If doc.hasitem("Body") Then
Set item = doc.getfirstitem("Body")
If item.type = 1 Then
'tests to see if this is a Rich Text  field
Forall o In item.EmbeddedObjects
If ( o.Type = EMBED_ATTACHMENT ) Then
'obviously point to it the right path
'if there is an uncertainty of where 
the file should go
'you will have to use Dir$ and mkdir to find or create
'when necessary
Call o.ExtractFile
( "c:\samples\" & o.Source )
End If
End Forall
End If
End If
'when done processing you can delete 
all the documents in one line
Call dc.RemoveAll(True)
End If

Can you help me create a LotusScript agent that I can use to delete email/documents before they become 30 days old?

Kinder: This code allows you to specify the age of documents that should be removed:

Dim session As New NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim dt As New NotesDateTime(Cstr(Now()))
Dim searchForm As String

Set db = session.CurrentDatabase

'this adjusts the current date, to 30 days previous
'but you can adjust however you want, 
you want to go backwards
'to set a target of documents for deletion
Call dt.AdjustDay(-30)

'searchForm is like a selection formula for a view, 
that helps you target 
'the documents you want to remove - 
the date adjustments are used in the
'searchForm, this sample assumes you are deleting 
emails and their form is always

searchForm = {Form = 
"Memo" & @Created <= [} & dt.LSLocalTime & {]}

Set dc = db.Search(searchForm, Nothing, 0)

If dc.Count > 0 Then
'this line deletes any documents found by the search,
 so make certain the code
'is running correctly with your adjustments before 
allowing this line to execute
Call dc.RemoveAll(True)
 End If

I use Lotus Notes 8.5. In a mask, I would like to create a button that opens a database with a specific frameset.

The code must be written in LotusScript, not Formula language because I need to open the local copy, even if the user is connected. Is this possible?

Kinder: This is actually possible using both LotusScript and Formula language. Basically, you would use the notes:// URL structure to do it. Here are samples from both Formula language and LotusScript.

Note: Remember to replace my markers with your server, database (full path) and frameset name. Also, this works for other objects like pages, forms and images.

Using Formula language:

srv := "";
fp := "path/dbname.nsf";
fs := "framesetname";

nurl := "notes://" + srv +"/" + fp 
+ "/" + fs + "?OpenFrameset";


Using LotusScript (requires UI elements):

Dim ws As New NotesUIWorkspace
Dim srv As String
Dim fp As String
Dim fs As String
Dim nurl As String

srv = ""
fp = "path/dbname.nsf"
fs = "framesetname"

nurl = "notes://" & 
srv & "/" & fp & "/" & fs + "?OpenFrameset"

Call ws.URLOpen(nurl)

Michael "Mike" Kinder is a senior application developer and administrator with over 15+ years experience in the Lotus Notes/Domino environment, including work with BlackBerry, Barracuda, Sametime, Quickr, and integration with other systems. He is hard at work on the e-Mail Assistant. Mike can be reached at

Dig Deeper on LotusScript

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...