|
|
|
|
|
|
|
|
|
|
|
|
|
|
A Fix for folders and documents (continued)
It would be tempting to use the document collection count, in code like this:
For i = 1 To doccoll.count
Set doc = doccoll.GetNthDocument(i)
If doc.folderreferences(0) <> "" Then 'doc is in at least one folder
Call doccoll.deletedocument(doc) 'pulls it from the collection
End If
Next
|
Sadly, this won't work, for two reasons. The For loop grabs the doccoll.count value when the For statement is executed the first time. Say there are 10 documents in the collection. While executing the loop, you remove documents from the collection. So the actual value of doccoll.count goes down by one, each time you circulate the loop.
But the For statements does not dynamically check i against doccoll.count -- for, I guess, performance reasons, it actually checks it against the value it grabbed at the start, which does not change while the loop executes. You remove 2 documents from the collection - there are now 8 left. But the For loop still expects to iterate to 10, so when it runs the 9th iteration, the if doc.folderreferences(0) line will cause an 'Object Not Set' error, because there is no 9th document in the collection any more.
The other fault is this: remove the 6th document, and what was the 7th becomes the sixth. But the loop, having processed the sixth, the code processes the now 7th document, and so skips one -- the one that moved from 7th to 6th when the old 6th one was removed.
I'm going back to bed. But before I do, I should also point out that Peter will still get one result he didn't expect. He says he told his agent to run on selected documents. However the code (line 8 in the complete example above) gets all the documents in the database. The agent selection specification is really for simple and formula agents, which are run once in their entirety for each selected document -- which also explains the presence of the 'Run Once' option.
LotusScript agents are always run just once, and do their own selection of documents. They have the ability to use NotesDatabase.UnprocessedDocuments to find the selected documents -- or new/modified documents if that's how the agent runs -- but the actual document selection is up to the agent code, and not up to Notes.
The Designer help says it all:
LotusScript and Java agents run once. You supply the search criteria and the iteration through the language constructs. Search criteria applied through the agent interface are effective only through UnprocessedDocuments in NotesDatabase (LotusScript) or UnprocessedDocuments in AgentContext (Java).
Now I really am going back to bed.
David Gewirtz is the author of How To Save Jobs and Where Have All The Emails Gone? For more than 20 years, he has analyzed current, historical, and emerging issues relating to technology, competitiveness, and policy. David is the Editor-in-Chief of the ZATZ magazines, is the Cyberterrorism Advisor for the International Association for Counterterrorism and Security Professionals, and is a member of the instructional faculty at the University of California, Berkeley extension. He can be reached at david@zatz.com and you can follow him at http://www.twitter.com/DavidGewirtz.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Advertisement --
Find unused Lotus Notes groups and clean up your address book
Have you ever wanted to get rid of old Lotus Notes groups that were cluttering up your address book, but you weren't sure if they were used? Find Unused Groups can help.
Find Unused Groups will check your ACL, mail, multi purpose and server groups to help you determine if they are used, and who uses them.
Learn how to easily clean up your address book. |
-- Advertisement --
Mark your calendar for in-depth Lotus training, May 12-14, Boston
Join experts and peers May 12-14 in Boston for educational and networking events that deliver real-world Lotus training so you can increase productivity and efficiency in your company, advance your skills, and squeeze the most from your current environment. One registration gets you into THE VIEW's Admin2010 and Lotus Developer2010.
Register by April 10 to save $200. |
|
|
|
|
|
|
|
|
|
|