Solved

Script Modification

Posted on 2003-11-26
10
663 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

16 Experts available now in Live!

Get 1:1 Help Now