Solved

Script Modification

Posted on 2003-11-26
10
659 Views
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                              
TryAgain:
            Set doc = documents.GetNextDocument (doc)
      Loop
      Call View.Refresh
      Msgbox Counter & " addresse(s) added out of  " & documents.count & " selected."
      Exit Sub
ErrorHandler:
      Msgbox "Error " & Err() & ":  " & Error() & ".  Some addresses may not have been added."
      Exit Sub
BadFromField:
      Msgbox "Error - From field contains unrecognizable characters.  Some addresses may not have been added."
      Goto TryAgain
      Exit Sub  

0
Comment
Question by:schmad01
  • 4
  • 3
  • 3
10 Comments
 
LVL 31

Expert Comment

by:qwaletee
ID: 9828876
Hi schmad01,

Replace:

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

With:

TryAgain:
          Dim nextDoc as notesDocument
          Set nextDoc = documents.GetNextDocument (doc)
          doc.remove
          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,
qwaletee
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 9832032
Schmad01,

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

like

Loop
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.

0
 
LVL 31

Expert Comment

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

Author Comment

by:schmad01
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?
0
 
LVL 24

Expert Comment

by:HemanthaKumar
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 ?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 31

Expert Comment

by:qwaletee
ID: 9850932
TryAgain:
          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.
0
 

Author Comment

by:schmad01
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.
0
 
LVL 24

Accepted Solution

by:
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" );
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 9854649
David,

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?
0
 

Author Comment

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now