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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DAOS - Backup / Restore 2 198
Lotus Notes Calendar Issue 5 115
how to install domino server on suse linux 18 94
Using @Prompt in a Queryclose Event 14 88
For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question ( here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

680 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