Skip to main content
Information Mgmt
New to Lotus
How to buy
Live demos
Technical library
Forums & community
Java™ technology
Open source
SOA and Web services
Web development
My developerWorks
About dW
Submit content

developerWorks  >  Lotus  >  Forums & community  >  Notes/Domino 6 and 7 Forum

Notes/Domino 6 and 7 Forum



Sign in to participate PreviousPrevious NextNext

Tamara Williams 5.Jan.10 03:58 PM a Web browser
Domino Designer 7.0 Windows Vista

Dear All:

I wrote an agent and I have a form that the user ineracts with. The user enters the person's name, cut-off date and attachment size. The agent finds the Names database from the server and searches in the hidden view ($VIMPeople) which has all names sorted by full name. It finds the document based on value in Name field on the Form and retrieves the person's mailbox path and db. It opens the person's mailbox and searches for documents created after the date specified and with attachment size larger than the amount specified. It then deletes the attachments and saves the document thus reducing storage size.

However, sometimes it finds and delete all attachments but most times it freezes up. I was hoping to delete both attachments and embedded objects but I am having serious problems with the code. The user has rights to all other person's mailbox. In the agent properties I also allow restricted operations with full admin rights. My code is shown below (I left out the variable declarations):

' Initialize
Set session=New NotesSession
Set db=session.CurrentDatabase

mimeFlag = session.ConvertMime
If mimeFlag = True Then
Print "MIME items are converted to rich text"
Print "MIME items are not converted to rich text"
End If
' Convert MIME to rich text
session.ConvertMime = True

' Current document
Set queryDocument = workspace.currentdocument

' Set defaults
msgQuery =""
attDeleted = False
objDeleted = False
embedDeleted = False

If Not queryDocument Is Nothing Then
' Clear fields
Call queryDocument.FieldSetText("mqfResult","")
Call queryDocument.Refresh

' Get current database server and path
' Check server name in organization component or organizational unit component
'serverName = Evaluate(|@Left(@Right(@ServerName;"CN=");"/OU=")|)

' Variant values are initialized to EMPTY so test for that value
'If (Isempty(serverName) Or serverName(0) = "") Then
serverName = Evaluate(|@Left(@Right(@ServerName;"CN=");"/O=")|)
'End If
'Print Cstr(serverName(0))+"#2"

' Get Names database from server
namesDbName = "names.nsf"
Set namesDb = New NotesDatabase(serverName(0),namesDbName)

If namesDb.IsOpen = True Then
' Open hidden view ($VIMPeople) which has names
Set namesView = namesDb.GetView("($VIMPeople)")
' Get document based on value in Name field on Query Form
Set userDocument = namesView.GetDocumentByKey(Cstr(queryDocument.FieldGetText("mqfName")))
' Get person's mailbox path and db
userMailboxPath = userDocument.MailFile(0)
Set userMailboxDb = New NotesDatabase(serverName(0),userMailboxPath)

If userMailboxDb.IsOpen = True Then

' Indicates whether or not a database has a full-text index.
If userMailboxDb.IsFTIndexed Then
' Updates the database full-text index (valid only for local databases)
Call userMailboxDb.UpdateFTIndex(True)
' Creates the database full-text index (valid only for local databases)
Call userMailboxDb.CreateFTIndex(options&,False)
End If

' Get and process results

' 1 MB = 1048576 B
attSize = queryDocument.FieldGetText("mqfAttachmentSize")
bytes = Cdbl(Csng(queryDocument.FieldGetText("mqfAttachmentSize")) * 1048576)
bytes = Round(bytes, 2)
'Print Cstr(bytes)

' @Created uses format dd/mm/yyyy so query={@Created >= [08/10/2009]}
' Format user date to server date format
Set tempDateTime = formatDate(Cstr(queryDocument.FieldGetText("mqfCutoffDate")))
query={@Created <= [}+Cstr(tempDateTime.DateOnly)+{] & @Sum(@Attachments > 0; @AttachmentLengths; 0) >= }+Cstr(bytes)

' Given selection criteria, returns all documents in a database that meet the criteria.
' Parameters are formula$, notesDateTime, maxDocs%
' so specify Nothing for notesDateTime to indicate no cutoff date and specify 0 for maxDocs% to receive all matching documents.
Set queryResultCollection = userMailboxDb.Search(query, Nothing, 0)

' To display to user. Format function formats the date/time.
msgQuery = "Search Criteria: "+ Chr$(13)+"Search "+Cstr(queryDocument.FieldGetText("mqfName"))+"'s mailbox for documents with Creation Date"
msgQuery =msgQuery + " <= " +Cstr(tempDateTime.DateOnly)+" ("+Cstr(Format(tempDateTime.DateOnly,"dd-mmm-yyyy"))+") "+" and total Attachment Size >= "+attSize +" MB"

If queryResultCollection.Count > 0 Then

countResult = queryResultCollection.Count
msgResults =msgResults + "Search Result: "+ Chr$(13)+"There are "+ Cstr(countResult)+ " document(s) found!"

Set queryResultDocument = queryResultCollection.GetFirstDocument
While Not queryResultDocument Is Nothing
' Reset values
attCount = 0
attTotal = 0
objCount= 0
objTotal= 0
attDeleted = False
objDeleted = False
embedDeleted = False

' Check if document contains one or more embedded objects, object links, or file attachments.
If queryResultDocument.HasEmbedded Then

If queryResultDocument.HasItem("Subject") Then
Set item = queryResultDocument.GetFirstItem( "Subject" )
'Set item2 = queryResultDocument.GetFirstItem( "From" )
subjectLine = Cstr(item.Text)
subjectLine = ""
End If
Print "Subject: " + subjectLine + " - search document #" + Cstr(countDocument+1)
'msgResults =msgResults +subjectLine+Chr$(9)

' Embedded Objects don't delete properly so accessing them a second time causes a crash so go to next document
' These apply to OLE Storage(Data) because other OLE Storage types are not recognized
If queryResultDocument.HasItem("mailboxQueryAgentObject") Then
'Goto nextLoop
End If

' The OLE/2 and OLE/1 embedded objects in a document.
' Unlike the EmbeddedObjects property in NotesRichTextItem, this property does not include file attachments,
' nor OLE/1 objects created in Notes Release 3.
' It accesses embedded objects so it requires permission to run so set agent properties security level and sign agent
If Not Isempty(queryResultDocument.EmbeddedObjects) Then
Forall o In queryResultDocument.EmbeddedObjects
Print "Object: "+Cstr(o.Name)
msgEmbedDetails = msgEmbedDetails +"Object Name: "+Cstr(o.Name)+Chr$(13)
Call o.Remove
' Set value because embedded objects don't delete properly and document should not be accessed again
Call queryResultDocument.Save(True, False)
objDeleted = True
embedDeleted = True
objCount = objCount +1
objTotal = objTotal + 1
End Forall
End If

' Body field can be RICHTEXT for rich text or MIME_PART for MIME support
Set rtitem = queryResultDocument.GetFirstItem("Body")

' All the embedded objects, object links, and file attachments contained in a rich text item.
If Not rtitem Is Nothing And Not Isempty(rtitem.EmbeddedObjects) Then
Forall o In rtitem.EmbeddedObjects

' Ignore embedded objects and object link in rich text item because it causes agent to crash
' use document embedded objects instead (see above)
If ( o.Type = EMBED_OBJECT) Then
msgEmbedDetails = msgEmbedDetails +"Body Field: Object Name: "+Cstr(o.Name)+ ", Body Field: Object Size: "+Cstr(Round(o.FileSize/1048576,3))+"MB"+ Chr$(13)
Call o.Remove
' Save at the end
'Call queryResultDocument.Save(True, False)
objDeleted = True
embedDeleted = True
objCount = objCount +1
objTotal = objTotal + 1
End If

' Check for file attachments.
If ( o.Type = EMBED_ATTACHMENT) Then
msgEmbedDetails = msgEmbedDetails +"Attachment Name: "+Cstr(o.Source)+ ", Attachment Size: "+Cstr(Round(o.FileSize/1048576,3))+"MB"+ Chr$(13)
Call o.Remove
' Save at the end
'Call queryResultDocument.Save(True, False)
attDeleted = True
embedDeleted = True
attCount = attCount + 1
attTotal = attTotal + 1
End If

End Forall

' Details for each search document
msgDetails = msgDetails + "Subject: "+ subjectLine+Chr$(13)+ "Date Composed: "+ Cstr(queryResultDocument.Created)+Chr$(13)
msgDetails = msgDetails + msgEmbedDetails
If (embedDeleted = True) Then
countDocument = countDocument + 1

' Totals for each documents
If objDeleted = True Then
msgTotalDetails = msgTotalDetails + Cstr(objCount) +" of " + Cstr(objTotal) + " object(s) were successfully removed!" + Chr$(13)
End If
If attDeleted = True Then
msgTotalDetails = msgTotalDetails + Cstr(attCount) +" of " + Cstr(attTotal) + " attachment(s) were successfully removed!" + Chr$(13)
End If
msgDetails = msgDetails + msgTotalDetails + Chr$(13)

' Add note about deletion to each mail document
Call rtitem.AddNewline(3)
docNote = "N.B. Maintenance deletion of files were performed on "+currentDateTime.DateOnly+" at "+currentDateTime.TimeOnly+" for: "
docNote = docNote +Chr$(13) + msgEmbedDetails+ msgTotalDetails
Call rtitem.AppendText(docNote)

'Indicate that this field has attachment deletions and used in replication settings at Documents by selection formula
'SELECT (!@Contains(@DocFields; "mailboxQueryAgentDelete"))
'Call queryResultDocument.Save(True, False)
End If

End If

End If

' Get next search result document
Set queryResultDocument = queryResultCollection.GetNextDocument(queryResultDocument)

msgResults =msgResults + " "+ Cstr(countDocument)+ " of " + Cstr(countResult)+ " document(s) have been processed successfully!"
' This means the documents with embedded objects are ignored so total document count is different
If (countResult <> countDocument) Then
msgResults =msgResults +" (The other document(s) contained Embedded Objects and have been processed already)"
End If

' No documents found
msgResults=msgResults + "Search Result: "+ Chr$(13)+"There are no documents found matching that search criteria!"
End If

' Person's mailbox doesn't exist
msgResults=msgResults + "Search Result: "+ Chr$(13)+Cstr(queryDocument.FieldGetText("mqfName"))+"'s mailbox does not exist!"
End If

' Names database from server doesn't exist
msgResults=msgResults + "Search Result: "+ Chr$(13)+"The Server's names.nsf database does not exist!"
End If

' Restore default MIME settings
session.ConvertMime = mimeFlag
' Display results to user
Call queryDocument.FieldSetText("mqfResult",msgQuery + Chr$(13) +Chr$(13) +msgResults + Chr$(13) +Chr$(13) + msgDetails)
Call queryDocument.Refresh

' The Query Form being used was closed etc
msgResults="The Query Form document does not exist!"
End If

' Display to status bar
Print msgQuery
Print msgResults

Exit Sub

Print "Error in Agent mailboxQueryAgent->Initialize line: "+Cstr(Erl)+" error:"+Error$+" error no: "+Cstr(Err)

Unable to delete attachments or emb... (Tamara Williams... 5.Jan.10)
. . Create a debug file log... (David Gilmore 6.Jan.10)

  Document options
Print this pagePrint this page

 Search this forum

  Forum views and search
Date (threaded)
Date (flat)
With excerpt
Advanced search

 Sign In or Register
Sign in
Forgot your password?
Forgot your user name?
Create new registration

 RSS feedsRSS
All forum posts RSS
All main topics RSS
More Lotus RSS feeds


Forum use and etiquette
Native Notes Access
Web site Feedback

Lotus Support

 Lotus Support
IBM Support Portal - Lotus software
Lotus Support documents
Lotus support by product
Lotus support downloads
Lotus support RSS feeds


IBM Composite Applications
IBM Mashup Center
IBM Connections
IBM Connections Cloud Developers
IBM Docs
IBM Forms
IBM Mobile Connect
IBM Sametime
IBM SmartCloud for Social Business
IBM Web Experience Factory
Lotus Domino
Lotus Domino Designer
Lotus Expeditor
Lotus Foundations
Lotus iNotes
Lotus Instructor Community Courseware
Lotus Notes
Lotus Notes & Domino Application Development
Lotus Notes Traveler
Lotus Protector
Lotus Quickr
Lotus Symphony
IBM Web Content Manager
WebSphere Portal

Lotus Forums

 Lotus Forums
Notes/Domino 9.0
Notes/Domino 8.5 + Traveler
Notes/Domino XPages development forum
Notes/Domino 8
Notes/Domino 6 and 7
IBM Connections
IBM Mobile Connect
IBM Sametime
IBM SmartCloud Notes
Lotus Enterprise Integration
Lotus Protector
Lotus Quickr
Lotus SmartSuite