Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Script Modification

Posted on 2003-11-26
Last Modified: 2013-12-18
Can someone add on to this script so that when it is done it will delete the selected documents?

      On Error Goto ErrorHandler
      On Error 183 Goto BadFromField      
      On Error 184 Goto BadFromField
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Set db = session.CurrentDatabase
      Dim view As NotesView
      Set view = db.GetView("AntiSpam")
      Dim documents As NotesDocumentCollection
      Set documents = db.UnprocessedDocuments
      Dim configdoc As NotesDocument
      Dim doc As NotesDocument
      Dim counter As Integer, FromField As String, startpos As Integer, endpos As Integer
REM Loop through selected memos to create persistent SpamCFG docs
      Set doc = documents.GetFirstDocument
      Do Until doc Is Nothing
            If doc.DeliveredDate(0)<>"" Then      ' it is indeed a memo I received vs. sent
                  Counter = Counter + 1  
                  Set configdoc = db.CreateDocument
                  getFromField = Evaluate("@Text(From)", doc)
                  FromField = getFromField(0)
                  Dim fromname As New NotesName(FromField)
                  internetaddress = fromname.Addr821                  
                  If internetaddress= "" Then ' must be Notes mail address
                        If doc.FromDomain(0) = "" Then  ' must be from my notes domain
                              getdomain = Evaluate("@Domain", doc)  
                              domain = getdomain(0)
                              getfrom =  fromname.abbreviated ' don't add domain to name
                        Else ' must be from another notes domain
                              domain = doc.FromDomain(0)
                              getfrom =  fromname.abbreviated & "@" & domain
                        End If
                  Else  ' it is an internet address
                        getfrom = FromField
                        pos = Instr(internetaddress, "@")
                        domain = Mid(internetaddress, pos+1)
                  End If
                  configdoc.From = getfrom
                  configdoc.Domain = "@" & domain
                  configdoc.IndividualOrDomain = "0"  ' set default to individual name
                  configdoc.Form = "SpamCFG"
                  REM do not want SpamCFG to show up in views other than AntiSpam
                  Dim ExcludeViews(1)
                  ExcludeViews(0) = "A"
                  ExcludeViews(1) = "D"
                  configdoc.ExcludeFromView = ExcludeViews
                  configdoc.HiddenDocument = "1"
                  REM save AntiSpam doc
                  Call configdoc.Save(True, False)
            End If                              
            Set doc = documents.GetNextDocument (doc)
      Call View.Refresh
      Msgbox Counter & " addresse(s) added out of  " & documents.count & " selected."
      Exit Sub
      Msgbox "Error " & Err() & ":  " & Error() & ".  Some addresses may not have been added."
      Exit Sub
      Msgbox "Error - From field contains unrecognizable characters.  Some addresses may not have been added."
      Goto TryAgain
      Exit Sub  

Question by:schmad01
  • 4
  • 3
  • 3
LVL 31

Expert Comment

ID: 9828876
Hi schmad01,


> TryAgain:
>           Set doc = documents.GetNextDocument (doc)


          Dim nextDoc as notesDocument
          Set nextDoc = documents.GetNextDocument (doc)
          Set doc = nextDoc

What this does:

For each document you process, after you have finished processing, you normally get the next document.  So, we want to put in a doc.remove before we move on to the next document.  The only problem is, once we remove the doc, we have no way of using the (now dearly departed) doc object to find the next doc.  So, we briefly use a temp doc object, nextDoc, to get the next document BEFORE we delete the previous (current) one.  Then, once we remove the current one, we assign the doc object, which is used everywhere, to the value of getNextDocument that was already pre-retrieved into nextDoc.

Best regards,
LVL 24

Expert Comment

ID: 9832032

Simply after the loop statement add documents.RemoveAll(true)


Call documents.RemoveAll(true) ' This will remove whole collection when it is done.
Call View.Refresh

But if you want to delete only selected docs which are processed as spam then you might have to create a new collection and add those docs which are spam and then remove the collection at the end.

LVL 31

Expert Comment

ID: 9834596
Good call, Hemantha.  The deletiondoes not have to be synchronous to the processing, and this eliminates the loop.  I forot about RemoveAll
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.


Author Comment

ID: 9850868
Ok, on qwal's suggestion I get:
57: Missing argument for :REMOVE

On Heman's I get:
Error 4241: Cannot remove NotesDocument when instantiated by NotesUIDocument. Some addresses may not have been added.

Any thoughts?
LVL 24

Expert Comment

ID: 9850920
Well it is weird, I don't see any NotesUIDocument in your script. Is this script run from an agent ? The collection is totally from background..isn't it ?
LVL 31

Expert Comment

ID: 9850932
          Dim nextDoc as notesDocument
          Set nextDoc = documents.GetNextDocument (doc)
          doc.remove true
          Set doc = nextDoc

But you could get the same error as Hemantha's code gives... if the open document is part of the UnprocessedDocuments collection that you are processing.

So, please explain what's going on here.  Since you are using UnprocessedDocumnts, I assuemd that this is in an agent.  Are you calling the agent from a button or hotspot or action bar on a form?  In that case, you shoudl close the document before running the agent.  Otherwuse,  can give you a workaround that will exclude the current document, but I still need info on exactly how the code is being called.

Author Comment

ID: 9852081
Yes, this is an agent.  And, I am running it from the preview window which may account for the doc being open problem. I would like a workaround for this as I use the document preview all the time.  Thanks.
LVL 24

Accepted Solution

HemanthaKumar earned 250 total points
ID: 9852263
ok that explains the error.

Right now there is no workaround, except to close the preview pane. So call the agent in conjunction with commands in view action buton

@Command([ShowHidePreviewPane]; "0");
@Command([ToolsRunMacro]; "Agent Name");
@PostedCommand([ShowHidePreviewPane]; "1" );
LVL 31

Expert Comment

ID: 9854649

hate to contradict Hemanth, but there is one other workaround.

You can delete all other documents besides the one that is open.  The question then becomes, what to do about the open one?  I believe you can delete it through the front end classes.

Would you like to work through this possibility?

Author Comment

ID: 9858070
Opening and closing of the preview pane works just great!  Thanks again.

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA Lotus notes 2 199
how to copy mail box rules from one nsf to another 9 183
Lotus notes email code 13 95
Scan to Email - HP 477 Printer and Lotus Notes 8 85
This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question